Skip to main content
15 events
when toggle format what by license comment
Oct 16, 2025 at 7:25 vote accept Ben
Oct 15, 2025 at 14:17 comment added Ian Abbott With glibc 2.38 or later, you can use #define _DEFAULT_SOURCE instead of #define _GNU_SOURCE to get the declaration of mempcpy (internally, it now uses __USE_MISC instead of __USE_GNU), but Ubuntu 22.04 only has glibc 2.35. Note that defining _GNU_SOURCE will automatically define _DEFAULT_SOURCE (which will define __USE_MISC) when the standard headers are included.
Oct 15, 2025 at 13:49 comment added Ian Abbott You should not #define __USE_GNU manually. It is for internal use by the headers.
Oct 15, 2025 at 7:17 history edited Ben CC BY-SA 4.0
added 47 characters in body
Oct 15, 2025 at 7:11 comment added Ben Adding #define _GNU_SOURCE does not work but adding #define __USE_GNU resolves the issue. I am sure I am compiling with -std=gnu17.
Oct 14, 2025 at 17:33 comment added John Bollinger Ah. I have found the source of my confusion, @ikegami. It seems that GCC does define _GNU_SOURCE by default when compiling C++, but it does not do so when compiling C. Or at least some versions do. That doesn't seem to be documented in the manual, though.
Oct 14, 2025 at 17:06 comment added ikegami @John Bollinger, I can replicate, including the fact that -std=gnu17 doesn't help. I tried using gcc 11.4.0 from Ubuntu 22.04.5 LTS, both under WSL2 and not. I get warning: implicit declaration of function ‘mempcpy’ [-Wimplicit-function-declaration] and warning: incompatible implicit declaration of built-in function ‘mempcpy’ [-Wbuiltin-declaration-mismatch]. See demo on Godbolt (where I used 15.2, and got an error instead of a warning).
Oct 14, 2025 at 16:48 comment added John Bollinger Are you sure you're compiling with -std=gnu17 in the new environment? Because that should not produce the issue you describe, but if you happened to switch to -std=c17 then that would explain everything.
Oct 14, 2025 at 16:44 comment added John Bollinger A compiler running in a WSL container does not rely on the Windows host for anything relevant to this question. For the same compilation command, the observed difference can arise only from a difference between the Linux installations in the two WSL containers, either version or configuration.
Oct 14, 2025 at 16:13 answer added ikegami timeline score: 5
Oct 14, 2025 at 15:46 comment added Blindy Alternatively, use memcpy, it's not like you're using the different return pointer. Or just use strcpy, which is actually what you're trying to use, and it's much more efficient to boot since it doesn't parse the source string twice (memcpy + strlen).
Oct 14, 2025 at 15:38 comment added 3CEZVQ man 3 mempcpy demonstrates how to #include string.h
Oct 14, 2025 at 15:33 comment added Eugene Sh. Add #define _GNU_SOURCE before the includes.
S Oct 14, 2025 at 15:22 review First questions
Oct 14, 2025 at 16:35
S Oct 14, 2025 at 15:22 history asked Ben CC BY-SA 4.0 created from wizard