How to correctly write declarations of extern arrays (and double arrays) in C's header files? How to correctly write declarations of extern arrays (and double arrays) in C's header files? arrays arrays

How to correctly write declarations of extern arrays (and double arrays) in C's header files?


This link discusses the problems with arrays and sizes used as extern and how to manage them.

  1. Declare a companion variable, containing the size of the array, defined and initialized (with sizeof) in the same source file where the array is defined
  2. define a manifest constant for the size so that it can be used consistently in the definition and the extern declaration

  3. Use some sentinel value (typically 0, -1, or NULL) in the array's last element, so that code can determine the end without an explicit size indication


The code you posted looks fine to me and compiles (gcc -std=c99 -pedantic and gcc -std=c90 -pedantic) on my machine. Have you copy-pasted these lines or could you have made a typo in your real header?

Example typos that could cause your error (pure guesswork):

extern int double_indexes[][];  /* forgot the 5 */extern int double_indexes[5][]; /* [] and [5] swapped */