3

I know the compiler sets the uninitialized array elements to 0 if the array is partially initialized.

int arr[3] = {3,1};

But is there a warning option in GCC or similar method to list partially initialized arrays?

Jason Hu
  • 1,237
  • 2
  • 15
  • 29
  • 1
    `-Wmissing-field-initializers` might be what you want. All I know is that I use the `no` version with `-Wall` and `-Wextra` because the warning is fairly annoying. – chris Jul 25 '13 at 00:58
  • 2
    `-Wmissing-field-initializers` seems to only work with structs, I just tested with an array and no warning : – Jason Hu Jul 25 '13 at 01:03
  • Odd, I was fairly sure I got warnings for arrays before I stuck that on. I guess my reason for taking it out *was* structures, though. – chris Jul 25 '13 at 01:04
  • 1
    I'm guessing there is no warning: http://stackoverflow.com/questions/10828294/c-and-c-partial-initialization-of-automatic-structure – Jiminion Jul 25 '13 at 02:22
  • @Jim ya that sucks :/ – Jason Hu Jul 25 '13 at 03:25
  • 3
    Just to be clear, setting uninitialized array elements to zero (*in this context*) is mandated by the language; it's not just gcc. – Keith Thompson Jun 09 '14 at 15:46

0 Answers0