On Mon, Mar 19, 2007 at 07:12:24PM -0300, Gustavo Rios wrote:
> I am writing a very simple program but the output change for the c
> variable value change every time i run it. What would it be my mistake
> on the source? Did i forget some thing?
> 
> #include <stdio.h>
> 
> int
> main(int argc, char **argv)
> {
>        unsigned long long      x, c;
>        unsigned                *p;
>
/* stop abusing the comma operator */
>        x = 1, x+= (unsigned long long)1 << 33 ;
/* Fine, storing random void * pointers in p is allowd */
>        p = (void *)&x;
/*
 * You assume that the in memory representation of an
 * unsigned [2] looks exactly like unsigned long long and you
 * expect to access the valid initialized memory of x by
 * dereferencing p.
 *
 * These assumptions are all wrong.
 */
>        c = p[0] * p[1];
> 
>        fprintf(stdout, "x:%llu\n", x);
>        fprintf(stdout, "0,1:%u,%u\n", p[0], p[1]);
>        fprintf(stdout, "c:%llu\n", c);
> 
>        return 0;
> }
> 
>

Your program is invalid. Gcc has all rights to fuck it up,
-omg-optimized or not.

Casts are basically syntactic sugar for "(i know what i'm doing, now
shut up and stop complaining)". Remove the (void *) and compile with
-Wall.

Tobias

Reply via email to