Structure initialization rules question

Michael Meissner meissner at dg_rtp.UUCP
Mon May 26 04:08:39 AEST 1986


In article <696 at moscom.UUCP> noemi at moscom.UUCP writes:
>
>	Why is it that you can only initialize structures when they are global
>	(outside of main() )?  If you initialize a structure within a function
>	you get an "No auto. aggregate initialization" error.  I don't see
>	anywhere in K&R where the structure initialization rules are explained.

    Under K&R (probably in appendix A where the real rules are spelled out)
it mentions that only aggreates (read arrays and structures) with static
storage (read static and global) can be initialized.  Ansi X3J11 (as of the
last meeting) allows initializing auto and register aggregates, providing
all members are constant.  The last constraint avoids some nasty problems
with regard to order of evaluation, and makes compilers unduely complex.

    As to why you could not initialize an auto aggregate, I think it was
because the PDP-11 did not have a block copy instruction, or that DMR did
not consider structures full fledged items (remember no structure arguments,
structure assignment, etc.).

	Michael Meissner, Data General
	...{ decvax, ihnp4, ... }!mcnc!rti-sel!dg_rtp!meissner



More information about the Comp.lang.c mailing list