2

I have a C file which is exhibiting some strange behavior. When I use id_t, the compiler claims it's not defined (it's defined in sys/types.h). Here's what's weird: I include sys/acl.h, which in turn includes sys/types.h. In the sys/acl.h header file itself, id_t is referenced, and the compiler doesn't complain about that. Further, when I remove my reference to it, the entire thing compiles properly, implying that the compiler hit sys/acl.h's use of id_t and didn't have a problem with it. Any idea what could be going on?

EDIT: sys/acl.h uses id_t in a define, which means it's not actually getting used; my bad on that one.

EDIT: using gcc -E (thanks for the tip, @kaylum), I figured out that the definition isn't getting included in the build. It's surrounded by the following guards:

#if (defined __USE_SVID || defined __USE_XOPEN || defined __USE_XOPEN2K8) \
    && !defined __id_t_defined
typedef __id_t id_t;
# define __id_t_defined
#endif

I tried using -D__USE_SVID, and it did nothing. I also tried adding #define __USE_SVID above the include statement, and it also did nothing.

EDIT: Figured it out; see this answer to another SO question. I switched to using -std=gnu99 (from -std=c99) and it worked.

Community
  • 1
  • 1
joshlf
  • 21,822
  • 11
  • 69
  • 96
  • You have it. Can you show it to us? – fuz Nov 23 '15 at 00:55
  • Sorry, what's "it" here? – joshlf Nov 23 '15 at 00:55
  • 2
    What is your compiler? If gcc then use the `-E` option to produce preprocessed output which should give you a clearer idea what is going on. – kaylum Nov 23 '15 at 00:55
  • So it turns out `sys/acl.h` doesn't actually use it - it only uses it in a define, and since that define isn't used, there's nothing to complain about. I confirmed the issue by using the define in my code; the compiler complained. – joshlf Nov 23 '15 at 00:59
  • As for the preprocessor output, you're right - the line isn't included. – joshlf Nov 23 '15 at 00:59
  • @joshlf I actually meant to look at the preprocessor output to see whether `id_t` is indeed defined. In `sys/types.h` the `id_t` definition is conditionally defined. On my system: `#if (defined __USE_SVID || defined __USE_XOPEN || defined __USE_XOPEN2K8)`. I don't know what all those conditions really represent but perhaps on your system they are all false for some reason. – kaylum Nov 23 '15 at 01:04
  • @joshlf “It” is the source code in question. – fuz Nov 23 '15 at 01:12

0 Answers0