Re: strange output on openbsd C code

2007-03-20 Thread Stuart Henderson
On 2007/03/19 19:12, 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. It doesn't do this on any system I've tried it on - >i386, amd64: x:8589934593 0,1:1,2 c:2 >sparc64: x:8589934593 0,1:2,1 c:2

Re: strange output on openbsd C code

2007-03-19 Thread Otto Moerbeek
On Mon, 19 Mar 2007, Matthew R. Dempsky wrote: > On Mon, Mar 19, 2007 at 09:55:04PM -0400, Paul D. Ouderkirk wrote: > > And because I love to reply to myself, if I compile it with -O3, I can > > reproduce your results: > > -O3 enables -fstrict-aliasing, which this program violates. The man > pag

Re: strange output on openbsd C code

2007-03-19 Thread Woodchuck
On Tue, 20 Mar 2007, Tobias Ulmer wrote: > /* > * 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. >

Re: strange output on openbsd C code

2007-03-19 Thread Tobias Ulmer
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 > > int > main(int argc, char **argv)

Re: strange output on openbsd C code

2007-03-19 Thread Matthew R. Dempsky
On Mon, Mar 19, 2007 at 09:55:04PM -0400, Paul D. Ouderkirk wrote: > And because I love to reply to myself, if I compile it with -O3, I can > reproduce your results: -O3 enables -fstrict-aliasing, which this program violates. The man page explains in more detail.

Re: strange output on openbsd C code

2007-03-19 Thread Darrin Chandler
On Tue, Mar 20, 2007 at 04:40:08AM +0200, [EMAIL PROTECTED] wrote: > Compile it with -O3. Then enjoy. Sure. Then I'll light my hair on fire and put it out with a ballpeen hammer. -- Darrin Chandler | Phoenix BSD Users Group [EMAIL PROTECTED] | http://bsd.phoenix.az.u

Re: strange output on openbsd C code

2007-03-19 Thread Adam
"Gustavo Rios" <[EMAIL PROTECTED]> 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? Bleh, what a depressing thread. Gustavo, why didn't you bother to prov

Re: strange output on openbsd C code

2007-03-19 Thread a . velichinsky
On Mon, Mar 19, 2007 at 07:17:46PM -0700, Darrin Chandler wrote: > 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

Re: strange output on openbsd C code

2007-03-19 Thread Darrin Chandler
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 > > int > main(int argc, char **argv)

Re: strange output on openbsd C code

2007-03-19 Thread Matthew R. Dempsky
On Tue, Mar 20, 2007 at 01:35:28AM +0100, Frank Denis wrote: > Le Mon, Mar 19, 2007 at 07:12:24PM -0300, Gustavo Rios ecrivait : > >I am writing a very simple program but the output change for the c > >variable value change every time i run it. > >int > >main(int argc, char **argv) > >{ > > u

Re: strange output on openbsd C code

2007-03-19 Thread Matthew R. Dempsky
On Mon, Mar 19, 2007 at 08:02:10PM -0400, Nick ! wrote: > Wait, how is * defined on two voids? That shouldn't even compile > (unless it's autocasting to int?). ``unsigned'' is short for ``unsigned int''. The ``(void *)'' cast is a red herring.

Re: strange output on openbsd C code

2007-03-19 Thread Paul D. Ouderkirk
On 3/19/07, Paul D. Ouderkirk <[EMAIL PROTECTED]> wrote: On 3/19/07, Gustavo Rios <[EMAIL PROTECTED]> wrote: > No! > > p sizeof is 4 bytes, p is the frst byt of &x, and p + 1 is the 4th > byte. Casting is only on attribution of &x to p. > > Realize, p[0] evals to 1 and p[1] evals to 2 as it shoul

Re: strange output on openbsd C code

2007-03-19 Thread Paul D. Ouderkirk
On 3/19/07, Gustavo Rios <[EMAIL PROTECTED]> wrote: No! p sizeof is 4 bytes, p is the frst byt of &x, and p + 1 is the 4th byte. Casting is only on attribution of &x to p. Realize, p[0] evals to 1 and p[1] evals to 2 as it should be. Only problem relates to p[0] * p[1]. I believe it should (1 *

Re: strange output on openbsd C code

2007-03-19 Thread David Higgs
Whenever a printf "fixes everything", it's usually because that forces gcc to put the values on the stack. Without the printf, they're probably in registers and p points to who knows what. If you grok assembly, try objdump on the executable to see what's going on. If you want to multiply the tw

Re: strange output on openbsd C code

2007-03-19 Thread Gustavo Rios
No! p sizeof is 4 bytes, p is the frst byt of &x, and p + 1 is the 4th byte. Casting is only on attribution of &x to p. Realize, p[0] evals to 1 and p[1] evals to 2 as it should be. Only problem relates to p[0] * p[1]. I believe it should (1 * 2), i.e., 2. Not a random value. On 3/19/07, Nick !

Re: strange output on openbsd C code

2007-03-19 Thread Frank Denis
Le Mon, Mar 19, 2007 at 07:12:24PM -0300, Gustavo Rios ecrivait : I am writing a very simple program but the output change for the c variable value change every time i run it. int main(int argc, char **argv) { unsigned long long x, c; unsigned*p; p = (voi

Re: strange output on openbsd C code

2007-03-19 Thread Nick !
On 3/19/07, Gustavo Rios <[EMAIL PROTECTED]> wrote: On 3/19/07, Nick ! <[EMAIL PROTECTED]> wrote: > On 3/19/07, Gustavo Rios <[EMAIL PROTECTED]> 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 mistak

Re: strange output on openbsd C code

2007-03-19 Thread Gustavo Rios
So, why when i printf p[1], it correctly prints 2? On 3/19/07, Nick ! <[EMAIL PROTECTED]> wrote: On 3/19/07, Gustavo Rios <[EMAIL PROTECTED]> 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

Re: strange output on openbsd C code

2007-03-19 Thread Nick !
On 3/19/07, Gustavo Rios <[EMAIL PROTECTED]> 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 int main(int argc, char **argv) { unsigned long

strange output on openbsd C code

2007-03-19 Thread Gustavo Rios
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 int main(int argc, char **argv) { unsigned long long x, c; unsigned*p;