Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com Message-ID: <002901bf8c9f$cef9f680$0201a8c0@jayk_home4nt> From: "Jay Krell" To: "swe sd" Cc: Subject: Re: problem in C++ pointer Date: Sun, 12 Mar 2000 19:54:16 -0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3612.1700 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3612.1700 >I just wonder what is the different between the original code >(using a single "cout", see test.cc attached) and new code >(use another cout to print ++X[0], above). The difference is that there is definitely a "sequence point" at every semicolon. The effects of code to the left of a semicolon are guaranteed to be visible before the effects of code to the right of the same semicolon. int i, j, k; F(j = i++, k = i++); is undefined, the parameters can be evaluated in any order even sort of simultaneously, whereas j = i++; k = i++; F(j, k); and k = i++; j = i++; F(j, k); are defined. The first line must be completely executed before the second line. > Actually, I tried the original program many time on my PC >running Cygnus. To remove external factor, I close all other >program after a re-boot. I got the same behavior as you, with 2.95.2 to as well. I tried reading the assembly (gcc -s x.cpp, then look at the file x.s) but it didn't include commented out C++ source so was too hard to follow. - Jay -----Original Message----- From: swe sd To: jay DOT krell AT cornell DOT edu Cc: cygwin AT sourceware DOT cygnus DOT com Date: Sunday, March 12, 2000 7:52 AM Subject: Re: problem in C++ pointer > First of all, thanks for you kindy answer ... > I have the last question. I rewrite the program as follow: > line 1: #include > 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 line 7: cout< line 8: X=A; > line 9: cout< line 10: <<*X< line 11: <<*X+5< line 12: <<*X<<" "< line 13: <<5+X[0]< line 14: <<( X[0]==0 ? "X[0]=0" : "X[0]!=0")< line 15: cout<<++X[0]< line 16: } > and executing it gives output: > $./a.out > 0 0x259fd7c 0x259fd7c > 0 0x259fd7c 0x259fd7c > 0 > 5 > 0 0 > 5 > X[0]=0 > 1 > Obviously, it gives the correct answer (line 7 = line 9). I >just wonder what is the different between the original code (using >a single "cout", see test.cc attached) and new code (use another >cout to print ++X[0], above). > Actually, I tried the original program many time on my PC >running Cygnus. To remove external factor, I close all other >program after a re-boot. But the result is still wrong (see last e-mail). > Then, to test my program is correct or not, I tried it on a >UNIX SVR with gcc compiler. Then the program works properly. > So, I just conclude there is some wrong with the cygwin, or >not as good as gcc. Thanks. >______________________________________________________ >Get Your Private, Free Email at http://www.hotmail.com > -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com