This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/15437] int vs const int computation: different answers


------- Additional Comments From lani at oas dot ca  2004-05-14 22:35 -------
Subject: Re:  int vs const int computation: different answers

Thank you for understanding what we were trying to say. This is the response we
were trying to find.

> In the first case, one computation is performed at compile- the other at 
> run-time. I understand that this seems weird here and maybe frustrating, 
> but there are good reasons for this. 

I appreciate that there are good reasons for this, and understand the
reasons. However, in principle no optimization should
cause int and const int to behave differently. It's way too
counter-intuitive. Compile time side-effects must be consistent with run-time
behavior, otherwise the optimization breaks rule #1 of optimization: any
optimization should not change the resulting computation.  This is the only
point we have been trying to make all along.

Thanks for the -O2 trick, we'll use that.


Sorry for the confusion, and thanks for a good discussion.

bangerth at dealii dot org writes :
> 
> 
> ------- Additional Comments From bangerth at dealii dot org  2004-05-14 22:13 -------
> I see your point, but I don't think you are entirely right. If you 
> store something in a 'const int' you tell the compiler that the value 
> of the variable won't change. The compiler can then do some simple 
> transformations based on this knowledge, without having to resort 
> to doing these things at run-time. Note that within the margin of 
> errors compiler-internal transformations and run-time behavior might 
> differ. 
>  
> If you just store it in an 'int', the compiler has to do some serious 
> investigations to figure out whether a variable is set only once or 
> not. Only if it is sure that it can't change can it do these transformation. 
> For gcc, these investigations are only performed if you ask for optimization. 
> Thus, you _do_ get the same result if you ask for them: 
>  
> g/x> c++ x.cc ; ./a.out  
> f(x) = 299 
> f(y) = 300 
>  
> g/x> c++ x.cc -O2 ; ./a.out  
> f(x) = 300 
> f(y) = 300 
>  
> In the first case, one computation is performed at compile- the other at 
> run-time. I understand that this seems weird here and maybe frustrating, 
> but there are good reasons for this. 
>  
> W. 
> 
> -- 
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15437
> 
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.
> 



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15437


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]