Click here to Skip to main content
15,885,435 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: what about x = x++; ? Pin
David Crow15-Sep-05 7:22
David Crow15-Sep-05 7:22 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 7:33
bugDanny15-Sep-05 7:33 
GeneralRe: what about x = x++; ? Pin
David Crow15-Sep-05 8:01
David Crow15-Sep-05 8:01 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 8:08
bugDanny15-Sep-05 8:08 
GeneralRe: what about x = x++; ? Pin
ky_rerun15-Sep-05 9:14
ky_rerun15-Sep-05 9:14 
GeneralRe: what about x = x++; ? Pin
David Crow15-Sep-05 9:22
David Crow15-Sep-05 9:22 
GeneralRe: what about x = x++; ? Pin
bugDanny16-Sep-05 2:51
bugDanny16-Sep-05 2:51 
AnswerRe: what about x = x++; ? Pin
Joaquín M López Muñoz15-Sep-05 6:51
Joaquín M López Muñoz15-Sep-05 6:51 
See this comp.lang.c faq[^] explaining why this is undefined behavior. Curiously enough, in C++ the expression works as you expect if you use some user defined type rather than a built-in integer:
class Integer
{
public:
  Integer(int i)...
  Integer operator++(int)... // postfix increment
  ...
};
 
Integer x=1;
x=x++; // x is now 1
because for user defined types, x++ is really a function call and so establishes a so-called sequence point --but this is not the case for built-in types. HTH.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!

-- modified at 12:54 Thursday 15th September, 2005
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 7:23
bugDanny15-Sep-05 7:23 
GeneralRe: what about x = x++; ? Pin
Joaquín M López Muñoz16-Sep-05 5:00
Joaquín M López Muñoz16-Sep-05 5:00 
GeneralRe: what about x = x++; ? Pin
bugDanny16-Sep-05 6:45
bugDanny16-Sep-05 6:45 
GeneralRe: what about x = x++; ? Pin
Joaquín M López Muñoz16-Sep-05 7:05
Joaquín M López Muñoz16-Sep-05 7:05 
GeneralRe: what about x = x++; ? Pin
bugDanny16-Sep-05 7:41
bugDanny16-Sep-05 7:41 
AnswerRe: what about x = x++; ? Pin
Anonymous15-Sep-05 8:30
Anonymous15-Sep-05 8:30 
GeneralRe: what about x = x++; ? Pin
Anonymous15-Sep-05 8:38
Anonymous15-Sep-05 8:38 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 8:57
bugDanny15-Sep-05 8:57 
GeneralRe: what about x = x++; ? Pin
Chris Losinger15-Sep-05 8:59
professionalChris Losinger15-Sep-05 8:59 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 9:05
bugDanny15-Sep-05 9:05 
GeneralRe: what about x = x++; ? Pin
David Crow15-Sep-05 9:32
David Crow15-Sep-05 9:32 
GeneralRe: what about x = x++; ? Pin
pesho293215-Sep-05 21:02
pesho293215-Sep-05 21:02 
GeneralRe: what about x = x++; ? Pin
David Crow16-Sep-05 2:15
David Crow16-Sep-05 2:15 
GeneralRe: what about x = x++; ? Pin
bugDanny16-Sep-05 3:15
bugDanny16-Sep-05 3:15 
GeneralRe: what about x = x++; ? Pin
pesho293216-Sep-05 3:36
pesho293216-Sep-05 3:36 
GeneralRe: what about x = x++; ? Pin
bugDanny16-Sep-05 4:19
bugDanny16-Sep-05 4:19 
GeneralRe: what about x = x++; ? Pin
pesho293218-Sep-05 21:48
pesho293218-Sep-05 21:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.