avoiding explicit array sizes (was: Point me in the right direction)

Guy Harris guy at auspex.UUCP
Sat Feb 25 06:44:06 AEST 1989


>	int	a[] = { 42, 666, ... };

You forgot 23 :-)

>	/* compiler will complain if sizeof(a)/sizeof(a[0]) is not equal
>	 * to NELT, thus ensuring that extern.c and header.h are in sync
>	 */

No, it won't necessarily.  It'll complain if the list of initializers
contains *more* than NELT elements; however, if it contains *fewer*
elements, it'll just silently initialize the rest to 0.  If this is
acceptable, fine, but if you want to make sure you initialize it with
*exactly* NELT elements, you need more help than the compiler will give
you....



More information about the Comp.lang.c mailing list