Bug 5051 - May I ask a C Language problem?
Summary: May I ask a C Language problem?
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-12-08 10:26 UTC by s9322036
Modified: 2005-11-10 03:18 UTC (History)
41 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description s9322036 2001-12-08 10:26:00 UTC
 This is a multi-part message in MIME format.
 
 ------=_NextPart_000_0007_01C18058.1D2CFED0
 Content-Type: text/plain;
 	charset="big5"
 Content-Transfer-Encoding: quoted-printable
 
 #define a(x) ((++x)*(++x))
 main()
 {
         int x=3D5;
         printf("%d\n",a(x));
 }
                                                                          =
       =20
 I type $ gcc filename.c -o a
 And execute $./a
 Under two systems, one is SunOS, and the other one is RH7.0+CLE1.0
 Sun is gcc-2.95; and under RH, I tried gcc version 2.96 and 3.0.2
 
 The results are as the following:                                        =
                                        =20
 RH is 49;
 SunOS is 42;
                                                                          =
       =20
 As we all know..
 The result should be 42!
 (5+1)*(6+1)=3D42.
                                                                          =
       =20
 Why my Linux compiler is wrong?
 How could I fix the problem?
                                                                          =
       =20
 Thanks for ur answer.
 And with regards.
 
 
 ------=_NextPart_000_0007_01C18058.1D2CFED0
 Content-Type: text/html;
 	charset="big5"
 Content-Transfer-Encoding: quoted-printable
 
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 <HTML><HEAD>
 <META http-equiv=3DContent-Type content=3D"text/html; charset=3Dbig5">
 <META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
 <STYLE></STYLE>
 </HEAD>
 <BODY bgColor=3D#ffffff>
 <DIV><FONT color=3D#008000><STRONG>#define a(x)=20
 ((++x)*(++x))<BR>main()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
 ; int=20
 x=3D5;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
 printf("%d\n",a(x));<BR>}</STRONG><BR></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
 p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
 ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
 nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
 bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
 sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
 p;&nbsp;=20
 <BR>I type $ gcc filename.c -o a<BR>And execute $./a<BR>Under two =
 systems, one=20
 is SunOS, and the other one is RH7.0+CLE1.0<BR>Sun is gcc-2.95; and =
 under RH, I=20
 tried gcc version 2.96 and 3.0.2</DIV>
 <DIV>&nbsp;</DIV>
 <DIV>The results are as the=20
 following:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
 sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
 p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
 ;&nbsp;&nbsp;&nbsp;&nbsp;&n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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
 nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
 bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
 <BR>Why my Linux compiler is wrong?<BR>How could I fix the=20
 problem?<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
 nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
 bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
 sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
 p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
 ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
 <BR>Thanks for ur answer.<BR>And with regards.<BR></DIV></BODY></HTML>
 
 ------=_NextPart_000_0007_01C18058.1D2CFED0--

Release:
unknown
Comment 1 Craig Rodrigues 2001-12-08 19:04:06 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Not a bug.
    If I compile your code with:
    gcc -Wall -pedantic test.c
    
    r.c:8: warning: operation on `x' may be undefined
    
    If I compile with the Digital Unix C++ compiler,
    I get a larger warning:
    
    cc: Warning: test.c, line 8: In this statement, the expression "printf(...)" modifies the variable "x" more than once without an intervening sequence point.  This behavior is undefined. (undefvarmod)
      printf ("%d\n", a (x));
    
    What you are doing is undefined, so can differ between
    compilers.
    
    This is not a bug in gcc.  Post your general C language questions
    to the newsgroup comp.lang.c.moderated
Comment 2 Craig Rodrigues 2001-12-09 03:04:07 UTC
From: rodrigc@gcc.gnu.org
To: gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org,
  nobody@gcc.gnu.org, s9322036@ncnu.edu.tw
Cc:  
Subject: Re: pending/5051: May I ask a C Language problem?
Date: 9 Dec 2001 03:04:07 -0000

 Synopsis: May I ask a C Language problem?
 
 State-Changed-From-To: open->closed
 State-Changed-By: rodrigc
 State-Changed-When: Sat Dec  8 19:04:06 2001
 State-Changed-Why:
     Not a bug.
     If I compile your code with:
     gcc -Wall -pedantic test.c
     
     r.c:8: warning: operation on `x' may be undefined
     
     If I compile with the Digital Unix C++ compiler,
     I get a larger warning:
     
     cc: Warning: test.c, line 8: In this statement, the expression "printf(...)" modifies the variable "x" more than once without an intervening sequence point.  This behavior is undefined. (undefvarmod)
       printf ("%d\n", a (x));
     
     What you are doing is undefined, so can differ between
     compilers.
     
     This is not a bug in gcc.  Post your general C language questions
     to the newsgroup comp.lang.c.moderated
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=5051&database=gcc
Comment 3 Andrew Pinski 2005-11-10 03:18:14 UTC
Reopening to ...
Comment 4 Andrew Pinski 2005-11-10 03:18:37 UTC
To mark as a dup of bug 11751.

*** This bug has been marked as a duplicate of 11751 ***