2

I'm writing an multithreaded application and I'm wondering about following: When using -D_REENTRANT macro, do I need to explicitly use _r suffixed functions?

e.g. Shall I use strtok_r everywhere in the code or can I use strtok and make sure I pass -D_REENTRANT macro to the compiler?

Thanks a lot

Jan Vorcak
  • 19,261
  • 14
  • 54
  • 90

1 Answers1

5

Defining _REENTRANT won't change the semantics of strtok(). You'll need to use strtok_r().

NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • In addition `-D_REENTRANT` is a no-op on any modern system. – R.. GitHub STOP HELPING ICE Apr 25 '14 at 12:31
  • thanks for the answer, @R.. can you please explain your comment a little bit more? – Jan Vorcak Apr 25 '14 at 12:53
  • 1
    Inspecting `features.h` on a glibc-based system, `_REENTRANT` causes `__USE_REENTRANT` to be defined. The only place where `__USE_REENTRANT` is ever checked, however, is for `getlogin_r` in `unistd.h`, and it's also exposed if `__USE_POSIX199506` is defined, which is defined in the default features profile. – R.. GitHub STOP HELPING ICE Apr 25 '14 at 19:56
  • 1
    I don't have any data for other systems right off except to say that the practice of having different versions of functions when `_REENTRANT` is defined was an ancient hack from when threads were new and scary to unix. There's no good reason to do things that way now, and lots of good reasons not to (subtle bugs if it's omitted when compiling some files). – R.. GitHub STOP HELPING ICE Apr 25 '14 at 19:58