Click here to Skip to main content
15,905,010 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Preprocessor Pin
toxcct27-Apr-04 5:55
toxcct27-Apr-04 5:55 
GeneralRe: Preprocessor Pin
Alexander M.,28-Apr-04 2:38
Alexander M.,28-Apr-04 2:38 
GeneralRe: Preprocessor Pin
David Crow27-Apr-04 10:01
David Crow27-Apr-04 10:01 
GeneralRe: Preprocessor Pin
toxcct27-Apr-04 23:20
toxcct27-Apr-04 23:20 
GeneralRe: Preprocessor Pin
Paul Ranson28-Apr-04 0:43
Paul Ranson28-Apr-04 0:43 
GeneralRe: Preprocessor Pin
Alexander M.,28-Apr-04 2:37
Alexander M.,28-Apr-04 2:37 
GeneralRe: Preprocessor Pin
David Crow29-Apr-04 3:11
David Crow29-Apr-04 3:11 
GeneralRe: Preprocessor Pin
Paul Ranson30-Apr-04 1:26
Paul Ranson30-Apr-04 1:26 
I meant that the compiler wouldn't generate any code for tests that only have one outcome.

This code,
#define MACRO(x,y) { x *= y; if (y == 3) x /= 2; }

int main()
{
 int iTemp = 10;
 MACRO( iTemp , 1 );
 MACRO( iTemp , 2 );
 MACRO( iTemp , 3 );
 MACRO( iTemp , 4 );

 std::cout << "Ends up with " << iTemp << std::endl ;

 return 0;
}

in an optimised build turns into
push 120
call ostream etc


IOW the compiler has taken all the fun out of it.

This function
int UseMacro ( int i )
{
 MACRO( i , 1 );
 MACRO( i , 2 );
 MACRO( i , 3 );
 MACRO( i , 4 );

 return i ;
}

compiles to
?UseMacro@@YAHH@Z PROC NEAR				; UseMacro, COMDAT

; 10   :  MACRO( i , 1 );
; 11   :  MACRO( i , 2 );
; 12   :  MACRO( i , 3 );

	mov	eax, DWORD PTR _i$[esp-4]
	lea	eax, DWORD PTR [eax+eax*2]
	shl	eax, 1
	cdq
	sub	eax, edx
	sar	eax, 1

; 13   :  MACRO( i , 4 );

	shl	eax, 2

; 14   : 
; 15   :  return i ;
; 16   : }

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

So I don't think we have to worry about optimising the Macro.

Interesting stuff to look at though, this is VC++ 7.1 and it seems pretty clever to me.

Paul
GeneralRe: Preprocessor Pin
David Crow29-Apr-04 3:08
David Crow29-Apr-04 3:08 
GeneralHelp needed: Swapping large data sets to file Pin
f.o.b27-Apr-04 4:56
f.o.b27-Apr-04 4:56 
GeneralRe: Help needed: Swapping large data sets to file Pin
f6427-Apr-04 6:14
f6427-Apr-04 6:14 
GeneralCharge Images from a PATH Pin
Hugo_Javier_Bertorello27-Apr-04 4:52
Hugo_Javier_Bertorello27-Apr-04 4:52 
GeneralRe: Charge Images from a PATH Pin
David Crow27-Apr-04 5:38
David Crow27-Apr-04 5:38 
GeneralRe: Charge Images from a PATH Pin
PJ Arends27-Apr-04 7:00
professionalPJ Arends27-Apr-04 7:00 
GeneralSystem wide CBT-Hook reacts only to windows in creating process Pin
Nick Nougat27-Apr-04 4:05
Nick Nougat27-Apr-04 4:05 
GeneralCFormView in a Dialog Based Aplication Pin
Carlos Sánchez García27-Apr-04 4:00
Carlos Sánchez García27-Apr-04 4:00 
GeneralThere's a simple solution Pin
Nitzan Shaked27-Apr-04 4:43
Nitzan Shaked27-Apr-04 4:43 
GeneralRuntime Error Pin
rrrado27-Apr-04 3:08
rrrado27-Apr-04 3:08 
GeneralRe: Runtime Error Pin
David Crow27-Apr-04 3:15
David Crow27-Apr-04 3:15 
GeneralRe: Runtime Error Pin
rrrado27-Apr-04 3:21
rrrado27-Apr-04 3:21 
GeneralRe: Runtime Error Pin
David Crow27-Apr-04 3:28
David Crow27-Apr-04 3:28 
GeneralRe: Runtime Error Pin
rrrado27-Apr-04 3:32
rrrado27-Apr-04 3:32 
GeneralRe: Runtime Error Pin
David Crow27-Apr-04 3:44
David Crow27-Apr-04 3:44 
GeneralRe: Runtime Error Pin
rrrado27-Apr-04 4:00
rrrado27-Apr-04 4:00 
GeneralRe: Runtime Error Pin
David Crow27-Apr-04 4:07
David Crow27-Apr-04 4:07 

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.