const, volatile, etc [was Re: #defines with parameters]
Peter Desnoyers
desnoyer at Apple.COM
Tue Dec 6 03:18:51 AEST 1988
In article <13784 at oberon.USC.EDU> blarson at skat.usc.edu (Bob Larson) writes:
>In article <21560 at apple.Apple.COM> desnoyer at Apple.COM (Peter Desnoyers) writes:
>>pet peeve - It is a common thing to have to write a zero to a device
>>register. The obvious code, (* reg_addr) = 0, often results in:
>>
>> xor reg_addr, reg_addr
>
>What machine is this for?
I'm pretty sure Turbo C on the PC does this. Even with optimization
off. I'll check.
>Most 68000 compilers would use the
>clr instruction, which does have the undesired side effect of doing
>an (ignored) read though.
>
Almost as bad. The important point is that if these
micro-optimizations are performed in the compiler pass of a pre-ANSI
compiler, there is NO way to turn them off. Thus the naive view that
everything worked fine before ANSI started messing with the language
is demonstrably wrong.
>>...(please correct me if I'm wrong ... [whether volatile specifies
>>one write and no reads]
I stand corrected. Thank you.
Peter Desnoyers
More information about the Comp.lang.c
mailing list