How compiler & language versions relate to each other
nia <[email protected]> Tue, 16 Jun 2026 11:11:40 +0000
| Newsgroups | gmane.os.netbsd.devel.packages |
|---|---|
| Message-ID | <[email protected]> |
GNU vs. C --------- -std=c99 is different from -std=gnu99. How is it different? The GCC documentation says it enables the "GNU dialect", but this is a simplification. What it does on several platforms is make every standard library function visible. Generally, it is much safer to use a "gnu" standard than a "c" standard for this reason. You can't necessarily predict which functions will be avaialble on which systems unless you are CERTAIN that the software is written to be strictly standards-conforming. Most software isn't. Even if it's written for C99, it probably uses functions from POSIX 2008. On NetBSD, it is not possible to use "alloca" with a "c" standard, only the "gnu" option. This varies between architectures, with amd64 being more forgiving than say, arm. On SunOS, the situation is more complicated, see: https://gist.github.com/jperkin/b08f9108daf8d0ac695067d71f882a9d Implicit function declarations ------------------------------ GCC 14 does not allow implicit function declarations. This means using a C function without including the appropriate header. "Who would do such a thing?" you ask. Well, many pieces of software rely on system C libraries transcluding other headers. Which header includes which other headers varies a _lot_ between operating systems. And which operating systems people test on isn't guaranteed. For foolproof results, read the actual standard documentation on the Open Group website to figure out which header to include. This is also relevant to the "gnu" discussion earlier, since it's easy to end up with implicit function declarations in a strict standards mode. GCC 14 is widespread in stable Linux distributions including Debian 13 and 14. New keywords ------------ GCC 15 (even 16) is widespread in Linux distributions such as Fedora and Ubuntu. It is the next version that NetBSD will updated to. It defaults to C23. What does this mean? C23 adds some new keywords, which are always visible. This means, that for example, a program uses the word "bool" as a variable name, it will no longer compile. Resources: https://gcc.gnu.org/gcc-15/porting_to.html Old style declarations ---------------------- In classic C dialects, you could leave a function prototype with empty arguments: void *malloc(); In C23, this needs to be: void *malloc(size_t); Resources: https://gcc.gnu.org/gcc-15/porting_to.html Issues with older C compilers ----------------------------- Different versions of GCC have different default languages. For example, a peiece of software might assume that a compiler defaults to C99, and use inline for loop variables: for (int i = 0; i < 100; ++i);; This is not allowed with GCC 4.x unless -std=(c|gnu)99 is passed to the compiler. Similarly, the last GPLv2 versions of GCC (including the version used by some OpenBSD ports) strictly enforce warning flags. You cannot use warning flags that it does not understand. Therefore, it's non-portable to fix the build on a newer compiler version by using -Wno-x to disable a warning. Better to fix the warning or force an older language standard with FORCE_C_STD, preferably a "gnu" variant unless you are CERTAIN the code does not use any later APIs.