Questions tagged [c17]

C17 is the informal name of the current standard (ISO/IEC 9899:2018) of the C programming language. It replaces C11, but introduces no new features. Instead the focus of C17 has been to resolve defect reports (DRs).

Filter by
Sorted by
Tagged with
1 vote
0 answers
62 views

No output for MSVC 2015! What to do? Should I change the C Standard on IDE?

Here's the c code: #include <stdio.h> typedef char charray5[5]; charray5 carr1 = { 'a', 'b', 'c', 'd', '\0' }; charray5 carr2 = { 'q', 'w', 'e', 'r', '\0' }; charray5 carr3 = { 'x', 'y', 'z', '...
0 votes
0 answers
51 views

Different size assigned to multiple variables which are declared continually in one statement [duplicate]

Trying to figure out why continued declaration is not a good Idea I suddenly realized the size assigned to following variables are not the same: char const* const ALPHA, BETA; printf("sizeof(...
  • 7,720
7 votes
1 answer
226 views

Is this C program with two struct definitions, involving a flexible array member, defined?

The fact that a struct with a flexible array member is a type with which a variable can be declared and to which sizeof can be applied leads to an unusual behavior in the following program. file fam1....
  • 78.6k
0 votes
0 answers
18 views

How to disable red error hint when I use variable sized array in C programming?

I have set the c_cpp extension standard to c17, and the code is running perfect normal in terminal! Nevertheless, there is still red underline in the code represent array's length, it's said "...
0 votes
1 answer
147 views

How to correctly downcast in C?

I'm currently limited to coding in C and I want to do C object oriented programming. One thing that comes to mind is how to correctly downcast a type in C without violating strict aliasing. Imagine I ...
  • 23.7k
1 vote
0 answers
50 views

Atomicity of compound assignment on _Atomic types: contradictory note in C standard

I noticed the C17 standard seems to contain a contradictory note about the atomicity of compound assignment (+=, etc) on atomic types. Working from the N2176 draft, which is allegedly the final ...
1 vote
0 answers
176 views

How to do closest guess on C99, C11 or C17?

I have a source code of C-project that has more than 600 c-files in it and it compiles for ARM mcu using GCC toolchain. I wonder how can I make a closest guess about which of the C standard this c-...
  • 13
5 votes
2 answers
156 views

clang/gcc cannot set global variables to an address constant minus another address constant

The program below compiles without errors. #include <stdio.h> char addr_a[8]; char addr_b[8]; unsigned long my_addr = (unsigned long)addr_b - 8; // PASS // unsigned ...
  • 109
0 votes
0 answers
137 views

Why don't tentative definitions cause errors due to multiple definitions? [duplicate]

The C17 standard says that If a translation unit contains one or more tentative definitions for an identifier, and the translation unit contains no external definition for that identifier, then the ...
1 vote
4 answers
134 views

What is the rationale for "semantics violation does not require diagnostics"?

Follow-up question for: If "shall / shall not" requirement is violated, then does it matter in which section (e.g. Semantics, Constraints) such requirement is located?. ISO/IEC 9899:202x (E) ...
  • 5,052
2 votes
2 answers
131 views

If "shall / shall not" requirement is violated, then does it matter in which section (e.g. Semantics, Constraints) such requirement is located?

If "shall / shall not" requirement is violated, then does it matter in which section (e.g. semantics, constraints) such requirement is located? Reason of the question: this opinion: This is ...
  • 5,052
0 votes
0 answers
91 views

Which implicit declarations are allowed / valid?

It is known that: implicit declaration of function is invalid implicit declaration of variable is invalid Which implicit declarations are allowed / valid? One example is identifier __func__. Are ...
  • 5,052
2 votes
1 answer
39 views

F.3 Operations, 9 lists 5 FE_ macros followed by 4 IEEE 754 rounding-direction attributes ending up with "respectively": mistake?

N2479 C17..C2x working draft — February 5, 2020 ISO/IEC 9899:202x (E): F.3 Operations, 9: The macros (7.6) FE_DOWNWARD, FE_TONEAREST, FE_TONEARESTFROMZERO, FE_TOWARDZERO, and FE_UPWARD, which are ...
  • 5,052
0 votes
3 answers
123 views

How to determine w/o conversions that a given floating constant can be represented?

How to determine w/o conversions that a given floating constant can be represented? Sample code: #define FLOATING_CONSTANT1 2147483647.0f #define FLOATING_CONSTANT2 2147483520.0f bool b1 = ...
  • 5,052
3 votes
3 answers
294 views

If 'float'<= INT_MAX is true, then why (int)'float' may trigger undefined behavior?

Sample code (t0.c): #include <stdio.h> #include <limits.h> #define F 2147483600.0f int main(void) { printf("F %f\n", F); printf("INT_MAX %d\...
  • 5,052
1 vote
4 answers
518 views

Is there such a thing as nullptr (or equivalent) in modern C standards?

I included a check for nullptr in a line of C code. The compiler (gcc) complained when using -std=c17 as well as -std=gnu17. Is there such a thing as nullptr (or equivalent) in modern C standards? (...
1 vote
2 answers
88 views

Does "strictly conforming program" + no extensions mean "no diagnostics emitted"?

Follow-up question for: clang: <string literal> + <expression returning int> leads to confusing warning: adding 'int' to a string does not append to the string. Does "strictly ...
  • 5,052
4 votes
2 answers
88 views

Can extension cancel the existing standard requirements?

Follow-up question for Why do conforming implementations behave differently w.r.t. incomplete array types with internal linkage?. Context: in both gcc and clang (conforming implementations) by default ...
  • 5,052
2 votes
1 answer
75 views

Is it possible to determine at compile time whether an implementation provides exact-width integer types? [duplicate]

Is it possible to determine at compile time whether an implementation provides exact-width integer types? Sample code (wanted): #include <stdint.h> #if HAS_EXACT_WIDTH_INTEGER_TYPES uint32_t ...
  • 5,052
-3 votes
1 answer
82 views

If an implementation supports extra nonstandard features, then is such implementation conforming?

Follow-up question for: Do unsupported standard features affect conformance?. Question: if an implementation supports extra features which are not described in the C standard, nor in any "...
  • 5,052
0 votes
1 answer
94 views

Do unsupported standard features affect conformance?

Context: C compilers deliberately do not support some features while being conforming implementations. Is it ok? Some examples. All of the compilers down below are conforming implementations (__STDC__ ...
  • 5,052
1 vote
3 answers
71 views

Which C rules allow to use in function declarator an identifier, which was previously defined as a type?

Consider this code (t0.c): typedef int T; void f(int T); Invocations: gcc -std=c11 -Wall -Wextra -pedantic -c t0.c <nothing> clang -std=c11 -Wall -Wextra -pedantic -c t0.c <nothing> cl /...
  • 5,052
2 votes
1 answer
48 views

Are HAS_SUBNORM and __STDC_IEC_559__ dependent?

Are HAS_SUBNORM and __STDC_IEC_559__ dependent? For example: If __STDC_IEC_559__ is 1, then HAS_SUBNORM is 1. If HAS_SUBNORM is 0, then __STDC_IEC_559__ is not 1.
  • 5,052
3 votes
2 answers
113 views

If the next representable value after -0.0 is +0.0, then why nextafter(-0.0, INFINITY) does not return +0.0?

If the next representable value after -0.0 is +0.0, then why nextafter(-0.0, INFINITY) does not return +0.0?
  • 5,052
0 votes
1 answer
153 views

C function declaration linkage

I'm a bit confused with a topic in the C17 standard. In 6.2.2, point 5 you can read: If the declaration of an identifier for a function has no storage-class specifier, its linkage is determined ...
  • 615
-1 votes
3 answers
104 views

Is there a standard way to prohibit reading (via assignment) of a variable?

It is known and useful features that: const type qualifier prohibits writing (modification) of a variable register storage-class specifier prohibits taking address of a variable However, is there a ...
  • 5,052
0 votes
1 answer
119 views

Is there any C compiler able to detect the violation of a "strictly conforming program"? [duplicate]

Is there any C compiler able to detect* the violation of a "strictly conforming program"? * under some option, for example, --accept-only-strictly-conforming-program If no, then which tools ...
  • 5,052
2 votes
3 answers
109 views

Is the term "format specifier" a synonym for term "conversion specifier"?

Both the C11 and C17 standards use terms “conversion specifier” and “format specifier”. Are they synonyms? If yes, then why introducing the synonyms? If no, then what is the difference between them?
  • 5,052
1 vote
1 answer
155 views

printf("%a"): how the format and parameters of hexadecimal floating-point constant are selected?

Consider this simple code (t0.c): #include <stdio.h> #include <float.h> #if DBL_HAS_SUBNORM == 1 double d = 0x23d804860c09bp-1119; int main(void) { printf("%a\n", d); ...
  • 5,052
0 votes
0 answers
40 views

Aligning/Format Output Values in C17

visual studio 2019, C17 I can't figure out how to get the output as in the example with different input data. example 1 expected output: 1234 1234 123 123 example 2 expected output: ...
  • 1
6 votes
4 answers
256 views

Which sections of the C standard prove the relation between the integer type sizes?

In the late draft of C11 [C11_N1570] and C17 [C17_N2176] I fail to find the proof of the following (which, I believe, is commonly known): sizeof(short) <= sizeof(int) <= sizeof(long) <= ...
1 vote
1 answer
97 views

Is there a standard way to check at compile time that file is being preprocessed only?

Context: all the compilers except __MY_CC__ are not supported. However, how to permit only preprocessing with a 3rd-party compiler? #if cc -E /* permit only preprocessing with a 3rd-party compiler ...
  • 5,052
1 vote
2 answers
186 views

Is there a standard way to guarantee that a certain (constant) expressions will be evaluated at compile (translation) time?

I am quite surprised that C does not guarantee that certain (constant) expressions are evaluated at compile (translation) time. C11 (6.6 Constant expressions) (emphasis added): A constant expression ...
  • 5,052
0 votes
1 answer
100 views

If unary operators have near the highest priority, then why the order of evaluation of # and ## operators is unspecified?

Simple question: if unary operators have near the highest priority, then why the order of evaluation of # and ## operators is unspecified? Relevant to both C and C++. C11 (6.10.3.2 The # operator): ...
  • 5,052
0 votes
0 answers
47 views

If FLT_HAS_SUBNORM is 0, then shall conversion (float)1E-45 return 0x1p-149?

Simple question: If FLT_HAS_SUBNORM is 0, then shall conversion (float)1E-45 return 0x1p-149? Reason of the question: ISO/IEC 9899:2011 (E) specifies behavior of FLT_HAS_SUBNORM / DBL_HAS_SUBNORM only ...
  • 5,052
1 vote
1 answer
154 views

Why Clang running on Windows has no C conformance (__STDC__ is not defined to 1)?

Sample code (t127.c): #include <stdio.h> int main(void) { int ret; #if __STDC__ == 1 printf("Has C conformance to version "); #if __STDC_VERSION__ printf("%ld", ...
  • 5,052
1 vote
1 answer
116 views

Why QNAN == QNAN does not lead to raising FE_INVALID exception?

Code (t125.c): #include <fenv.h> #include <stdint.h> #include <stdio.h> #if _MSC_VER #pragma fenv_access (on) #else #pragma STDC FENV_ACCESS ON #endif void show_fe_exceptions(void) ...
  • 5,052
0 votes
4 answers
142 views

C standard: structure and union specifiers: what is the exact definition of 'suitably converted'?

N2479 C17..C2x working draft — February 5, 2020 ISO/IEC 9899:202x (E) (emphasis added): 6.7.2.1 Structure and union specifiers 17    Within a structure object, the non-bit-field members and the units ...
  • 5,052
1 vote
2 answers
360 views

Can I treat an `enum` variable as an `int` in C17?

TL;DR: Is it right to assume, given enum NAME {...};, that enum NAME n is the same as int n during execution? Can n be operated on as if it were a signed int, even though it is declared as enum NAME? ...
2 votes
1 answer
358 views

Why converting 'out of range integer to integer' leads to IB, but converting 'out of range floating-point to integer' leads to UB?

Follow-up question for: Type casting: double to char: multiple questions Assigning an unsigned value to a signed char Context: ISO/IEC 9899:202x (E) working draft — February 5, 2020 C17..C2x N2479 (...
  • 5,052
0 votes
0 answers
86 views

If the presence of subnormal numbers is optional (HAS_SUBNORM), then why the presence of FP_SUBNORMAL is mandatory?

If the presence of subnormal numbers is optional (HAS_SUBNORM feature macros), then why the presence of FP_SUBNORMAL classification macro is mandatory? Reason of the question: in this (still ...
  • 5,052
4 votes
2 answers
131 views

Why not all the standard headers are preceded with std prefix?

Why not all the standard headers are preceded with std prefix? I.e. why complex.h and not stdcomplex.h?
  • 5,052
4 votes
2 answers
129 views

Does name of stdatomic.h contradict with (potential) restriction of the mapping to eight significant characters before the period?

ISO/IEC 9899:2011 (E): 6.10.2.5 The implementation may ignore distinctions of alphabetical case and restrict the mapping to eight significant characters before the period. Since stdatomic.h has 9 ...
  • 5,052
0 votes
2 answers
93 views

Does -Wpedantic make the program follow the -std=version?

If I use gcc -std=c17, will -Wpedantic issue warnings for c17? Is this the same as ISO C?
user avatar
4 votes
1 answer
130 views

Is fpclassify(x) == FP_NAN functionally equivalent to isnan(x)?

Is fpclassify(x) == FP_NAN functionally equivalent to isnan(x)? The same question goes for: fpclassify(x) == FP_INFINITE vs. isinf(x) fpclassify(x) == FP_NORMAL vs. isnormal(x) fpclassify(x) == ...
  • 5,052
1 vote
1 answer
120 views

Is assignment x=1; always an undefined behaviour according to C17?

I'm looking at the final draft of C17, N2176. Here, I'm concerned with what kind of expression with side effects would have it's behaviour undefined. In section 6.5 Expressions of the standard, there ...
  • 117
2 votes
2 answers
154 views

What rules are there for qualifiers of effective type?

So I was re-reading C17 6.5/6 - 6.5/7 regarding effective type and strict aliasing, but couldn't figure out how to treat qualifiers. Some things confuse me: I always assumed that qualifiers aren't ...
  • 189k
-1 votes
1 answer
61 views

Is program translation direction well-defined?

It may sound obvious, but just out of curiosity: is program translation direction well-defined (i.e. top-to-bottom, left-to-right)? Is it explicitly defined in the standard?
  • 5,052
2 votes
5 answers
265 views

Bitwise & over 32 bits

#include <stdio.h> #include <limits.h> int main() { unsigned long long a = 9223372036854775808; // a = 2^63 a = a & ~1; printf("%llu\n", a); printf("%d, ...
  • 695
4 votes
3 answers
162 views

Contradiction in C18 standard (regarding character sets)?

We read in the C18 standard: 5.1.1.2 Translation phases The precedence among the syntax rules of translation is specified by the following phases. Physical source file multibyte characters are ...
  • 615