Default Rules: Extensions
Since there have been some discussions about the use of GCC extensions, I decided to make a default-rules post about it. How should we deal with compiler extensions to languages?
The answer header must specify …
3y ago
The `C (gcc)` implies extensio …
3y ago
Implementation defines the lan …
3y ago
3 answers
The answer header must specify the minimum implementation & environment required
If there are multiple implementations of a language and an answer depends on features of one, it must be specified. Otherwise, it can just specify the language.
That specification can be done mostly in any form, as long as it's complete (or unspecified things are the default). In general, there shouldn't be a need to specify a precise version of an implementation, but if there's explicit reliance on it, it should be noted too.
For example, "C (gcc)" specifies that gcc
must be used, with the default settings. "C (clang 12) -std=c11
+ boost" means clang-12
with the "ISO C 2011" standard and the boost library. "C" alone would mean any implementation that follows the standard. (whether a standard can be considered an implementation by itself is a separate question)
0 comment threads
The C (gcc)
implies extensions - it will only work with that specific compiler under it's default setting GNU17 (equivalent to -std=gnu17
), which is mostly a superset of standard C. This also includes a number of POSIX functions.
Another option is standard C, meaning no extensions and no constraint or syntax violations. This would be equivalent to gcc -std=c17 -pedantic-errors
. As a subset of standard C, there is yet another option: strictly conforming standard C, meaning there can also be no poorly-defined behavior.
The definition of a strictly conforming program can be found in C17 4/5:
A strictly conforming program shall use only those features of the language and library specified in this International Standard. It shall not produce output dependent on any unspecified, undefined, or implementation-defined behavior, and shall not exceed any minimum implementation limit.
Solutions in standard C and/or strictly conforming should be labelled as such by the poster. Otherwise, the default behavior of the specific compiler with no options passed to it is assumed to apply.
C++ (g++) behaves mostly the same, though in C++ there's also the boost library which has to be included explicitly. I think boost is to be regarded as any 3rd party lib and solutions using it will then be C++ with boost
.
0 comment threads
Implementation defines the language, so if you use extensions to a language, you should add + ... extensions
to the header.
E.g. for a C post using gcc extensions, the header begin with
# C (gcc) + gcc extensions
0 comment threads