strict-aliasing and typedefs

Andreas Schwab schwab@suse.de
Wed May 14 21:21:00 GMT 2003


Brad Lucier <lucier@math.purdue.edu> writes:

|> I've read the documentation and done a google and gcc search, but
|> I still have this question.
|> 
|> If I have the typedefs and variables
|> 
|> typedef int stackslot;
|> typedef int heapslot;
|> 
|> stackslot *sp;
|> heapslot *hp;
|> 
|> then can sp and hp point to the same location in memory with
|> ISO C's aliasing rules?

Yes.  Typedefs don't introduce new types, just new names.  The following
is completely equivalent:

typedef int stackslot;
typedef int heapslot;

int *sp;
int *hp;

|> I'm wondering if a Scheme->C compiler
|> can use typedefs and ISO C's aliasing rules to tell gcc that certain
|> memory locations cannot alias each other.

One way to do this is to define differently named structures with a single
member, but they may pessimize the generated code due to ABI
peculiarities.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



More information about the Gcc mailing list