Structure alignment question

David Chase rbbb at rice.EDU
Fri Sep 5 04:07:55 AEST 1986


Suppose I have a structure "foo" and function returning a "struct foo".

    struct foo {
	int a,b;
	};
    struct foo bar() {
	struct foo baz;
	...
	return baz;
	};

Note that the structure contains two ints.  I will assume that an "int" is
the same size as some machine quantity called a "word", and that
word alignment is desirable.  I assume therefore that all instances of the
structure generated by the compiler will be word-aligned.

C compilers that I have seen supporting structure-valued functions pass a
hidden parameter to the function containing the address to store the
result.

Can a compiler assume that the storage for the result is word-aligned?
(That is, can a compiler make the same assumptions when returning a
structure that it does when assigning a structure?)
If so, why?  If not, why not?

David



More information about the Comp.lang.c mailing list