Quantcast
Channel: C Pre-Processor Macro code with () and {} - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by P.P for C Pre-Processor Macro code with () and {}

$
0
0

In addition to other answers,

unsigned int d = {1,2,3};

(after macro substitution)

is not valid in C. It violates 6.7.9 Initialization:

No initializer shall attempt to provide a value for an object not contained within the entity being initialized.

With stricter compilation options (gcc -std=c17 -Wall -Wextra -pedantic test.c), gcc produces:

warning: excess elements in scalar initializer     unsigned int d = {1,2,3};                         ^

However, note that

unsigned int d = {1};

is valid because initializing scalar with braces is allowed. Just the extra initializer values that's the problem with the former snippet.


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>