You got me there :-) Yes you are right. The reason I gave for dead code elimination is not sound! Should have thought a bit before writing :-(
Uday. Axel Freyn wrote, On Wednesday 15 September 2010 12:05 AM:
Hello Uday, On Tue, Sep 14, 2010 at 11:50:11PM +0530, Uday P. Khedker wrote:[..] The point is: in your program is is only a pointer. When you pass s as a parameter to printf, the compiler assumes that only s is being used so the (effective) assignment *s = 'H' is deleted as dead code when optimization is enabled.I can't believe your argumentation is correct. Wouldn't that mean: When I have a code, where I only pass the pointer to a function like: void f(int *); int main(){ int *s = (int *)malloc(100,sizeof(int)); for(int i = 0; i< 100; ++i) s[i] = 0; f(s); free(s); } The compiler would be allowed to erase the complete for-loop? And thus the initialization of the array? Or I did misunderstand your argumentation... Axel
