Click here to Skip to main content
15,893,814 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ShellExe to execute any exe ,,,, what si to close it Pin
Anthony_Yio6-Jun-04 20:42
Anthony_Yio6-Jun-04 20:42 
GeneralRe: ShellExe to execute any exe ,,,, what si to close it Pin
Zeeshan Bilal6-Jun-04 20:56
Zeeshan Bilal6-Jun-04 20:56 
GeneralRe: ShellExe to execute any exe ,,,, what si to close it Pin
Antony M Kancidrowski6-Jun-04 22:39
Antony M Kancidrowski6-Jun-04 22:39 
QuestionCAN i access Video Camera through COM port Pin
Zeeshan Bilal6-Jun-04 18:22
Zeeshan Bilal6-Jun-04 18:22 
Generaltoolobar question Pin
User 5838526-Jun-04 18:20
User 5838526-Jun-04 18:20 
GeneralRe: toolobar question Pin
Michael Dunn6-Jun-04 19:48
sitebuilderMichael Dunn6-Jun-04 19:48 
GeneralMSDataGrid Pin
Alton Williams6-Jun-04 18:07
Alton Williams6-Jun-04 18:07 
Questionwill this be compiler(M$ cl) bug or Memory leakage? Pin
DengJW6-Jun-04 17:14
DengJW6-Jun-04 17:14 
 #include <iostream.h>
 #define unsafe(i)  \
         ( (i) >= 0 ? (i) : -(i) )
 
 inline
 int safe(int i)
 {
   return i >= 0 ? i : -i;
 }
  int f() {cout << "Called f()!" << endl; return 0;};
  void userCode(int x)
 {
   int ans;
   ans = unsafe(x++);   // Error! x is incremented twice
   cout << "[1] "<< x << endl;
//   ans = (f()) >= 0 ? (f()) : -(f()); 
   ans = unsafe(f());   // Danger! f() is called twice
    cout <<  "[2] "<< x << endl;

   ans = safe(x++);     // Correct! x is incremented once
      cout <<  "[3] "<< x << endl;
   ans = safe(f());     // Correct! f() is called once
      cout <<  "[4] "<< x << endl;
 } 

 void main(void)
 {
   userCode(100);
 }


I was doing a test code for inline functions comparison to macros. The original code was shown as above, things seemed normal as the result showed two times of f() calls. The result looked like:

[1] 102
Called f();
Called f();
[2] 102
[3] 103
Called f();
[4] 103


However, after I tried to call <big>ans = (f()) >= 0 ? (f()) : -(f()); </big> instead of <big>ans = unsafe(f());</big>, I got a result of calling f() FOUR times instead of TWO times as supposed. In this tread, I failed to attach a image of the result, which looked like:

[1] 102
Called f();
Called f();
Called f();
Called f();
[2] 102
[3] 103
Called f();
[4] 103


I ran the program twice both of times I got calling f() FOUR times, nevertheless, I could repeat the result after I re-compiled the program again with the original code.

Could this be a compiler bug?


DJ
AnswerRe: will this be compiler(MS cl) bug or Memory leakage? Pin
Michael Dunn6-Jun-04 19:56
sitebuilderMichael Dunn6-Jun-04 19:56 
GeneralRe: will this be compiler(MS cl) bug or Memory leakage? Pin
DengJW6-Jun-04 20:06
DengJW6-Jun-04 20:06 
GeneralMoveWindow shrinking my dialog Pin
Vadim Tabakman6-Jun-04 14:04
Vadim Tabakman6-Jun-04 14:04 
GeneralRe: MoveWindow shrinking my dialog Pin
Anthony_Yio6-Jun-04 17:07
Anthony_Yio6-Jun-04 17:07 
GeneralRe: MoveWindow shrinking my dialog Pin
Vadim Tabakman6-Jun-04 18:07
Vadim Tabakman6-Jun-04 18:07 
GeneralRe: MoveWindow shrinking my dialog Pin
Anthony_Yio6-Jun-04 20:37
Anthony_Yio6-Jun-04 20:37 
GeneralRe: MoveWindow shrinking my dialog Pin
Vadim Tabakman7-Jun-04 16:15
Vadim Tabakman7-Jun-04 16:15 
GeneralRe: MoveWindow shrinking my dialog Pin
User 5838526-Jun-04 18:48
User 5838526-Jun-04 18:48 
Questionhow can I change the color of status bar Pin
woyaojinqu6-Jun-04 13:14
woyaojinqu6-Jun-04 13:14 
AnswerRe: how can I change the color of status bar Pin
bneacetp6-Jun-04 13:35
bneacetp6-Jun-04 13:35 
AnswerRe: how can I change the color of status bar Pin
Cedric Moonen6-Jun-04 20:43
Cedric Moonen6-Jun-04 20:43 
QuestionHow to support Drag 'n Drop out of ZIP archive onto an Applications window / Desktop program icon ? Pin
Defenestration6-Jun-04 11:57
Defenestration6-Jun-04 11:57 
AnswerRe: How to support Drag 'n Drop out of ZIP archive onto an Applications window / Desktop program icon ? Pin
Anthony_Yio6-Jun-04 17:10
Anthony_Yio6-Jun-04 17:10 
AnswerRe: How to support Drag 'n Drop out of ZIP archive onto an Applications window / Desktop program icon ? Pin
Michael Dunn6-Jun-04 20:01
sitebuilderMichael Dunn6-Jun-04 20:01 
GeneralPlease Help!!!I'm disperate Pin
Nemok6-Jun-04 10:21
Nemok6-Jun-04 10:21 
GeneralRe: Please Help!!!I'm disperate Pin
FreeLemons6-Jun-04 10:27
FreeLemons6-Jun-04 10:27 
GeneralRe: Please Help!!!I'm disperate Pin
Nemok8-Jun-04 6:06
Nemok8-Jun-04 6:06 

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.