Optimizing of explicit temporary storage
Mark Mitchell
mark@codesourcery.com
Tue Oct 12 12:19:00 GMT 2004
Robert Dewar wrote:
> Mark Mitchell wrote:
>
>> In C, even given just:
>>
>> (void) malloc(16);
>>
>> it would be surprising to most programmers to optimize away the call
>> because malloc *does* have side-effects on real systems. For
>> example, on UNIX, it is likely to call sbrk, which result in
>> observable changes in the process state.
>
>
> Yes, but the condition of not surprising programmers is different from
> the condition of conforming to the standard. Strictly from a standards
> conformance point of view, these kinds of optimization seem perfectly
> valid, but of course the criterion of not surprising programmers is
> indeed a reasonable one!
I'm not sure stanadards are all that relevant here, since most real C
programs go beyond the set of library functions standardized by ISO, or
even POSIX.
The as-if rule says that the compiler can perform the optimization only
if the program can't tell the difference. I don't think it means "can't
tell the difference using functions from the ISO C standard library;"
instead, I think it means "can't tell the difference in the current
environment." Certainly, calling malloc has observable side effects on
most UNIX systems; I can see whether or not processes are calling malloc
by running "top".
--
Mark Mitchell
CodeSourcery, LLC
(916) 791-8304
mark@codesourcery.com
More information about the Gcc
mailing list