5

All of the examples I see in manpages and online suggests <unistd.h>. CLion suggested the more c++ friendly <csignal>.

Looking into <csignal> on my g++ setup, I ended up in a rabbit hole and gave up in <c++config.h>.

If I want a c++ friendly/c++ adopted header. Which one should I use?

Captain Giraffe
  • 14,407
  • 6
  • 39
  • 67
  • 3
    Just stick to the man pages, it's not a c++ function, just use the posix header – Alan Birtles May 15 '22 at 19:25
  • 1
    As you identified, there's an `isatty` function defined in the POSIX C header `unistd.h`. If that's the function you want to use, is there a reason that you can't include `unistd.h`? [C++ should have no problem interfacing with POSIX libraries](https://stackoverflow.com/q/29952576/11082165) in most cases. – Brian61354270 May 15 '22 at 19:25
  • 1
    `isatty` is a Unix thing, so `"unistd.h"` is probably the right header. `` just pulls in the contents of `` (and puts the non-macro names into `std`), so you get `sig_atomic_t`, `raise`, and `signal`. That's all. – Pete Becker May 15 '22 at 19:25
  • Unless any of you want to answer this question. I'm going to self-answer based on the three comments above in about half an hour. – Captain Giraffe May 15 '22 at 19:34

1 Answers1

1

Random C headers/libraries might pose a problem interfacing with c++ code. In particular using keywords as names.

This is not the case with posix headers.

I'm using <unistd.h> in all my future cases.

Captain Giraffe
  • 14,407
  • 6
  • 39
  • 67
  • With regards to using C headers that use C++ keywords as identifiers, some advice can be found here: [How can I include a C header that uses a C++ keyword as an identifier in C++?](https://stackoverflow.com/q/72177535/11082165) – Brian61354270 May 15 '22 at 19:50