Click here to Skip to main content
15,888,174 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Better Way Pin
Laxman Auti5-Jun-06 19:57
Laxman Auti5-Jun-06 19:57 
GeneralRe: Better Way Pin
HakunaMatada5-Jun-06 20:08
HakunaMatada5-Jun-06 20:08 
GeneralRe: Better Way Pin
Viorel.5-Jun-06 20:10
Viorel.5-Jun-06 20:10 
GeneralRe: Better Way Pin
Maxwell Chen5-Jun-06 20:18
Maxwell Chen5-Jun-06 20:18 
GeneralRe: Better Way Pin
Viorel.5-Jun-06 20:36
Viorel.5-Jun-06 20:36 
AnswerRe: Better Way Pin
Maxwell Chen5-Jun-06 21:29
Maxwell Chen5-Jun-06 21:29 
GeneralRe: Better Way Pin
Viorel.5-Jun-06 22:28
Viorel.5-Jun-06 22:28 
GeneralRe: Better Way Pin
Maxwell Chen5-Jun-06 23:06
Maxwell Chen5-Jun-06 23:06 
With your method,
  NDEBUG, /MT, /Ot, /O2,
there is no difference between "if-else" and "?: operator" in the listing ASM code.

And regarding to the performance, ?: operator is a little faster.

Result:
9754 (if-else) (ignored, warm-up exercise)
9323 (? : ) (ignored, warm-up exercise)
9223 (if-else)
9214 (? : )


ASM code:
?TestI@@YAHH@Z PROC					; TestI, COMDAT

; 5    : 	volatile static int k = n; // prevents removing of calls    

	mov	eax, 1
	test	BYTE PTR ?$S1@?1??TestI@@YAHH@Z@4IA, al
	jne	SHORT $LN8@TestI
	or	DWORD PTR ?$S1@?1??TestI@@YAHH@Z@4IA, eax
	mov	DWORD PTR ?k@?1??TestI@@YAHH@Z@4HC, 3
$LN8@TestI:

; 6    : 	if(n==0 || n==1)
; 7    : 		return n;
; 8    : 	return -1;

	or	eax, -1

; 9    : }

	ret	0
?TestI@@YAHH@Z ENDP					; TestI
?TestO@@YAHH@Z PROC					; TestO, COMDAT

; 13   : 	volatile static int k = n; // prevents removing of calls    

	mov	eax, 1
	test	BYTE PTR ?$S2@?1??TestO@@YAHH@Z@4IA, al
	jne	SHORT $LN8@TestO
	or	DWORD PTR ?$S2@?1??TestO@@YAHH@Z@4IA, eax
	mov	DWORD PTR ?k@?1??TestO@@YAHH@Z@4HC, 3
$LN8@TestO:

; 14   : 	return (n == 0 || n == 1) ? n : -1;

	or	eax, -1

; 15   : }

	ret	0
?TestO@@YAHH@Z ENDP					; TestO



Maxwell Chen
GeneralRe: Better Way Pin
Viorel.5-Jun-06 23:20
Viorel.5-Jun-06 23:20 
GeneralRe: Better Way Pin
Maxwell Chen5-Jun-06 23:29
Maxwell Chen5-Jun-06 23:29 
AnswerRe: Better Way Pin
Hamid_RT5-Jun-06 22:22
Hamid_RT5-Jun-06 22:22 
QuestionUPDATE DATA Pin
yogendra kaushik5-Jun-06 19:02
yogendra kaushik5-Jun-06 19:02 
AnswerRe: UPDATE DATA Pin
Maxwell Chen5-Jun-06 19:14
Maxwell Chen5-Jun-06 19:14 
QuestionHow to know that application is closed. that was launched by ShellExecute() Pin
zahid_ash5-Jun-06 18:50
zahid_ash5-Jun-06 18:50 
AnswerRe: How to know that application is closed. that was launched by ShellExecute() Pin
Ganesh_T5-Jun-06 18:55
Ganesh_T5-Jun-06 18:55 
GeneralRe: How to know that application is closed. that was launched by ShellExecute() Pin
zahid_ash5-Jun-06 18:58
zahid_ash5-Jun-06 18:58 
GeneralRe: How to know that application is closed. that was launched by ShellExecute() Pin
khan++5-Jun-06 19:06
khan++5-Jun-06 19:06 
AnswerRe: How to know that application is closed. that was launched by ShellExecute() Pin
khan++5-Jun-06 18:58
khan++5-Jun-06 18:58 
AnswerRe: How to know that application is closed. that was launched by ShellExecute() Pin
Laxman Auti5-Jun-06 20:04
Laxman Auti5-Jun-06 20:04 
AnswerRe: How to know that application is closed. that was launched by ShellExecute() Pin
sunit55-Jun-06 20:11
sunit55-Jun-06 20:11 
GeneralRe: How to know that application is closed. that was launched by ShellExecute() Pin
sunit55-Jun-06 20:37
sunit55-Jun-06 20:37 
AnswerRe: How to know that application is closed. that was launched by ShellExecute() Pin
Viorel.5-Jun-06 20:28
Viorel.5-Jun-06 20:28 
AnswerRe: How to know that application is closed. that was launched by ShellExecute() Pin
2249175-Jun-06 23:00
2249175-Jun-06 23:00 
Questionrunning an application using command prompt Pin
zahid_ash5-Jun-06 18:45
zahid_ash5-Jun-06 18:45 
AnswerRe: running an application using command prompt Pin
Ganesh_T5-Jun-06 18:52
Ganesh_T5-Jun-06 18:52 

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.