From: "Jay Krell" <jay.krell@cornell.edu>
To: "swe sd" <ccwork@hotmail.com>, <cygwin@sourceware.cygnus.com>
Subject: Re: problem in C++ pointer
Date: Sat, 11 Mar 2000 16:33:00 -0000 [thread overview]
Message-ID: <003501bf8bba$e51882f0$0201a8c0@jayk_home4nt> (raw)
Darn, sent that before finishing..
>something like, skipping endl.
>cout.<<(A[0]).<<(" ").<<(&A).<<(" ").<<(&A[0]).<<(*X).<<(*X+5).<<(*X).<<("
>").<<A[0].<<(5+X[0]).<<(( X[0]==0 ? "X[0]=0" : "X[0]!=0")).<<(++X[0]);
something like, skipping endl.
cout
.print(A[0])
.print(" ")
.print(&A)
.print(" ")
.print(&A[0])
.print(*X)
.print(*X+5)
.print(*X)
.print(" ")
.printA[0]
.print(5+X[0])
.print(( X[0]==0 ? "X[0]=0" : "X[0]!=0"))
.print(++X[0]);
whether or not the left of the dots is supposed to be evaluated before the
right and the parameters to "print", I'm not sure. See "sequence point" in
the standard..
- Jay
-----Original Message-----
From: Jay Krell <jay.krell@cornell.edu>
To: swe sd <ccwork@hotmail.com>; cygwin@sourceware.cygnus.com
<cygwin@sourceware.cygnus.com>
Date: Saturday, March 11, 2000 4:31 PM
Subject: Re: problem in C++ pointer
>Your code might be triggering undefined behavior in C++, because of the
>++X[0] in the same statement where you otherwise read X[0]. Definitely
>something like
>printf("%d%d", X[0], ++X[0]);
>is undefined but I've read something along the lines that when the
>operators are actually overloaded, function calls, that the order of
>evaluation becomes defined..
>
>> line 9: cout<<A[0]<<" "<<&A<<" "<<&A[0]<<endl
>> line 10: <<*X<<endl
>> line 11: <<*X+5<<endl
>> line 12: <<*X<<" "<<A[0]<<endl
>> line 13: <<5+X[0]<<endl
>> line 14: <<( X[0]==0 ? "X[0]=0" : "X[0]!=0")<<endl
>> line 15: <<++X[0]<<endl
>
>something like, skipping endl.
>cout.<<(A[0]).<<(" ").<<(&A).<<(" ").<<(&A[0]).<<(*X).<<(*X+5).<<(*X).<<("
>").<<A[0].<<(5+X[0]).<<(( X[0]==0 ? "X[0]=0" : "X[0]!=0")).<<(++X[0]);
>
> - Jay
>
>-----Original Message-----
>From: swe sd <ccwork@hotmail.com>
>To: cygwin@sourceware.cygnus.com <cygwin@sourceware.cygnus.com>
>Date: Saturday, March 11, 2000 9:31 AM
>Subject: B20: problem in C++ pointer
>
>
>> I compiled the following program (attachment test.cc):
>> line 1: #include <iostream>
>> line 2: void main()
>> line 3: { const int size=10;
>> line 4: int A[size];
>> line 5: int *X=NULL, i;
>> line 6: for (i=0;i<size;i++) A[i]=i;
>> line 7: cout<<A[0]<<" "<<&A<<" "<<&A[0]<<endl;
>> line 8: X=A;
>> line 9: cout<<A[0]<<" "<<&A<<" "<<&A[0]<<endl
>> line 10: <<*X<<endl
>> line 11: <<*X+5<<endl
>> line 12: <<*X<<" "<<A[0]<<endl
>> line 13: <<5+X[0]<<endl
>> line 14: <<( X[0]==0 ? "X[0]=0" : "X[0]!=0")<<endl
>> line 15: <<++X[0]<<endl
>> line 16: }
>> and executing it gives output:
>> $./a.out
>> 0 0x259fd7c 0x259fd7c
>> 1 0x259fd7c 0x259fd7c
>> 1
>> 6
>> 1 1
>> 6
>> X[0]!=0
>> 1
>> Obviously, the output of line 9 is different from line 7 which should
>be
>>the same indeed. Is there anything wrong ? Thanks.
>>
>>______________________________________________________
>>Get Your Private, Free Email at http://www.hotmail.com
>>
>
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
next reply other threads:[~2000-03-11 16:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-03-11 16:33 Jay Krell [this message]
-- strict thread matches above, loose matches on Subject: below --
2000-03-17 13:26 Heribert Dahms
2000-03-17 13:15 Jay Krell
2000-03-17 9:48 Jay Krell
2000-03-16 8:39 James Stern
2000-03-13 2:07 Jay Krell
2000-03-13 1:54 Bernard Dautrevaux
2000-03-12 19:51 Jay Krell
2000-03-12 7:52 swe sd
2000-03-12 0:06 Jay Krell
2000-03-11 21:20 swe sd
2000-03-11 16:29 Jay Krell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='003501bf8bba$e51882f0$0201a8c0@jayk_home4nt' \
--to=jay.krell@cornell.edu \
--cc=ccwork@hotmail.com \
--cc=cygwin@sourceware.cygnus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).