User account creation filtered due to spam.

Bug 10947 - ++ postfix operator increments too soon
Summary: ++ postfix operator increments too soon
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.2.2
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-23 02:26 UTC by Barry Mead
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: I am sorry I don't know what goes in here
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 Barry Mead 2003-05-23 02:26:05 UTC
With the following line of code:
*s++ = toupper(*s);
The 3.2.2 gcc increments s before the value is determined on the right side of
the equal sign.  So what happens is *s gets the value of toupper(*s+1) not
toupper(*s)
The bug did not occur in version 3.1.1 of gcc.  I have not run tests on versions
in-between these versions.  The gcc version 3.2.2 is the standard one that is
included in the Mandrake Linux 9.1 distribution.  If a known fix for this is
possible by recompiling gcc 3.2.2 or upgrading to a newer gcc please let me know.
Comment 1 Andrew Pinski 2003-05-23 02:35:06 UTC
Subject: Re: [Bug c/10947] New: ++ postfix operator increments too soon

This is a bug in your code, you are violating sequence point rules, you 
cannot access something that you increment.

Use the option -Wsequence-point for a warning about them.

   -Wsequence-point        Warn about possible violations of sequence 
point rules

you can do this instead:

{*s = toupper(*s); s++;}

Thanks,
Andrew Pinski

PS can someone close this bug.



> With the following line of code:
> *s++ = toupper(*s);
> The 3.2.2 gcc increments s before the value is determined on the right 
> side of
> the equal sign.  So what happens is *s gets the value of toupper(*s+1) 
> not
> toupper(*s)
> The bug did not occur in version 3.1.1 of gcc.  I have not run tests 
> on versions
> in-between these versions.  The gcc version 3.2.2 is the standard one 
> that is
> included in the Mandrake Linux 9.1 distribution.  If a known fix for 
> this is
> possible by recompiling gcc 3.2.2 or upgrading to a newer gcc please 
> let me know.

Comment 2 Eric Botcazou 2003-05-23 04:50:02 UTC
See Andrew comment. Not a bug.
Comment 3 Nathanael C. Nerode 2003-05-23 05:56:03 UTC
confirmed invalid
Comment 4 Wolfgang Bangerth 2004-08-13 16:01:18 UTC
Reopening to mark as a duplicate of... 
Comment 5 Wolfgang Bangerth 2004-08-13 16:05:17 UTC
. 
Comment 6 Wolfgang Bangerth 2004-08-13 16:05:40 UTC
...PR 11751 

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