swrap icon indicating copy to clipboard operation
swrap copied to clipboard

Strange interaction with standard headers in C99 mode with GCC

Open ghost opened this issue 5 years ago • 3 comments

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

ghost avatar Sep 06 '19 02:09 ghost

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?

BareRose avatar Sep 06 '19 05:09 BareRose

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

ghost avatar Sep 06 '19 05:09 ghost

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.

ghost avatar Sep 06 '19 11:09 ghost