Click here to Skip to main content
15,899,754 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: A funny thing happened to me. Who can explain? Pin
David Crow13-May-04 5:41
David Crow13-May-04 5:41 
GeneralRe: A funny thing happened to me. Who can explain? Pin
toxcct13-May-04 5:44
toxcct13-May-04 5:44 
GeneralRe: A funny thing happened to me. Who can explain? Pin
David Crow13-May-04 6:28
David Crow13-May-04 6:28 
GeneralRe: A funny thing happened to me. Who can explain? Pin
toxcct13-May-04 6:35
toxcct13-May-04 6:35 
GeneralRe: A funny thing happened to me. Who can explain? Pin
David Crow13-May-04 6:48
David Crow13-May-04 6:48 
AnswerRe: A funny thing happened to me. Who can explain? Pin
vividtang14-May-04 0:29
vividtang14-May-04 0:29 
GeneralRe: A funny thing happened to me. Who can explain? Pin
Anand Paranjpe14-May-04 0:37
Anand Paranjpe14-May-04 0:37 
AnswerRe: A funny thing happened to me. Who can explain? Pin
Anand Paranjpe14-May-04 0:34
Anand Paranjpe14-May-04 0:34 
this is because of compiler optimization. Just have a look at assembly code.

const int a=10;
0041B1CE mov dword ptr [a],0Ah
int* p=(int*)&a;
0041B1D5 lea eax,[a]
0041B1D8 mov dword ptr [p],eax
*p=100;
0041B1DB mov eax,dword ptr [p]
0041B1DE mov dword ptr [eax],64h
int i=a;
0041B1E4 mov dword ptr [i],0Ah

Also while printing on console...

cout << "a=" << a << endl;
0041B291 push offset std::endl (4194BAh)
0041B296 push 0Ah
0041B298 push offset string "a=" (44E0C8h)
0041B29D push offset std::cout (457668h)
0041B2A2 call std::operator<<<std::char_traits<char> > (419A96h)
0041B2A7 add esp,8
0041B2AA mov ecx,eax
0041B2AC call std::basic_ostream<char,std::char_traits<char> >::operator<< (4195DCh)
0041B2B1 mov ecx,eax
0041B2B3 call std::basic_ostream<char,std::char_traits<char> >::operator<< (419AC3h)

You will not experience this behavour with all the compilers.

Thanks,

Anand

The chosen One Smile | :)
GeneralSharing violation error when loading a DLL Pin
DaFrawg13-May-04 1:08
DaFrawg13-May-04 1:08 
GeneralRe: Sharing violation error when loading a DLL Pin
bikram singh13-May-04 5:28
bikram singh13-May-04 5:28 
GeneralRe: Sharing violation error when loading a DLL Pin
DaFrawg23-May-04 22:45
DaFrawg23-May-04 22:45 
GeneralCapture Video from tv Tunner card Pin
Anonymous13-May-04 1:03
Anonymous13-May-04 1:03 
GeneralRe: Capture Video from tv Tunner card Pin
marcosvpp13-May-04 5:00
marcosvpp13-May-04 5:00 
GeneralESP error calling DLL exported function... Pin
Chris Ulliott13-May-04 0:54
Chris Ulliott13-May-04 0:54 
GeneralRe: ESP error calling DLL exported function... Pin
Justin Cooke13-May-04 4:19
Justin Cooke13-May-04 4:19 
GeneralRe: ESP error calling DLL exported function... Pin
bikram singh13-May-04 5:13
bikram singh13-May-04 5:13 
GeneralDrawThemeText Pin
Steve Thresher13-May-04 0:53
Steve Thresher13-May-04 0:53 
GeneralNetwork I/O models Pin
Rickard Andersson2012-May-04 23:51
Rickard Andersson2012-May-04 23:51 
GeneralRe: Network I/O models Pin
Mike Dimmick13-May-04 3:27
Mike Dimmick13-May-04 3:27 
GeneralInstead a dialog I want to appear 3 buttons Pin
Filomela12-May-04 23:30
Filomela12-May-04 23:30 
GeneralRe: Instead a dialog I want to appear 3 buttons Pin
nguyenvhn13-May-04 1:50
nguyenvhn13-May-04 1:50 
GeneralRe: Instead a dialog I want to appear 3 buttons Pin
Filomela13-May-04 21:42
Filomela13-May-04 21:42 
GeneralRe: Instead a dialog I want to appear 3 buttons Pin
nguyenvhn13-May-04 22:41
nguyenvhn13-May-04 22:41 
GeneralTerminate a Named Program Pin
sweep12312-May-04 23:27
sweep12312-May-04 23:27 
GeneralRe: Terminate a Named Program Pin
Milton Karimbekallil12-May-04 23:56
Milton Karimbekallil12-May-04 23:56 

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.