swrap
swrap copied to clipboard
Strange interaction with standard headers in C99 mode with GCC
I was having trouble getting swrap to compile in C99 mode with GCC, but then I put
#undef _DEFAULT_SOURCE
#define _DEFAULT_SOURCE 1
at the top of a .c file that #includes swrap.h
and it worked. Sources: 1 2
When something like stdio.h
is included, it doesn't work by simply putting the snippet in or directly above the #include
of swrap.h
. You have to put the snippet above all includes in the translation unit to be safe.
I have attached a test case. Try compiling it both ways. swrap_c_test.zip
Neat, will have a closer look at that weirdness when I can. Hopefully a solution can be found that won't require awkwardly redefining _DEFAULT_SOURCE
everywhere.
What version of GCC and what specific OS are you using BTW?
I don't have it in front of me, but it's Ubuntu 18.04. _DEFAULT_SOURCE
was defined in ~2015 I think.
On September 5, 2019 11:05:15 PM MDT, BareRose [email protected] wrote:
Neat, will have a closer look at that weirdness when I can. Hopefully a solution can be found that won't require awkwardly redefining
_DEFAULT_SOURCE
everywhere.What version of GCC and what specific OS are you using BTW?
-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/BareRose/swrap/issues/4#issuecomment-528709712
GCC 7.4.0. But I'm not sure if this is a bug in GCC; it also fails with Clang. Clang does use GCC headers though, so maybe.
It compiles just fine with TCC, and I don't know where TCC's headers come from on Linux. TCC is more of a pure C compiler that I have a fondness for, but it has to work in GCC and Clang.