Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22002

How to make incomplete array/struct initialization an error or warning? [duplicate]

$
0
0

If we define an array/struct like this:

int a[5] = { 1, 2, 3, };struct b { int c; int d; } e = { 1, };

or even:

int a[5] = { 1, 2, 3 };struct b { int c; int d; } e = { 1 };

we get no error from C compiler as the missing elements are initialized with a 0 default, like when we write explicitly:

int a[5] = { 1, 2, 3, 0, 0 };struct b { int c; int d; } e = { 1, 0 };

Is there a way to disable the default initialization of an array in C, so that the compiler gives an error or warning when the elements are not all defined?

I am using gcc 4.8.0 (MinGW).


Viewing all articles
Browse latest Browse all 22002

Trending Articles



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