Click here to Skip to main content
15,906,624 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralCapture and CHANGE ip packets Pin
kydfru21-Nov-04 3:22
kydfru21-Nov-04 3:22 
GeneralRe: Capture and CHANGE ip packets Pin
benjymous21-Nov-04 22:50
benjymous21-Nov-04 22:50 
QuestionWhat to replace macro in C/C++? Pin
Link260021-Nov-04 2:32
Link260021-Nov-04 2:32 
AnswerRe: What to replace macro in C/C++? Pin
Jörgen Sigvardsson21-Nov-04 2:38
Jörgen Sigvardsson21-Nov-04 2:38 
GeneralRe: What to replace macro in C/C++? Pin
Ryan Binns21-Nov-04 17:48
Ryan Binns21-Nov-04 17:48 
GeneralRe: What to replace macro in C/C++? Pin
Jörgen Sigvardsson21-Nov-04 21:22
Jörgen Sigvardsson21-Nov-04 21:22 
AnswerRe: What to replace macro in C/C++? Pin
John R. Shaw21-Nov-04 5:46
John R. Shaw21-Nov-04 5:46 
GeneralRe: What to replace macro in C/C++? Pin
Link260021-Nov-04 14:04
Link260021-Nov-04 14:04 
Okay, this is no simple stack class, this is the stack template class
that used in an advanced 3D application -- Doom 3. This is the source
from idsoftware. They used two macros here in a stack template.

idStack(type, next) and STACK_NEXT_PTR( element ) to simplify the
usage. Since many books suggest to avoid macro in C++, and now that
I'm looking at the code from idsoftware, I've been wondering if
there is a way to replace macro. How they used macro in the code
below seems very clever to me.

Note: The code is free and downloadable from idsoftware.

// Copyright (C) 2004 Id Software, Inc.

#define idStack( type, next )	idStackTemplate<type, (int)&(((type*)NULL)->next)>

template< class type, int nextOffset >
class idStackTemplate {
public:
	idStackTemplate( void );

	void	Add( type *element );
	type *	Get( void );

private:
	type *	top;
	type *	bottom;
};

#define STACK_NEXT_PTR( element )  (*(type**)(((byte*)element)+nextOffset))

template< class type, int nextOffset >
idStackTemplate<type,nextOffset>::idStackTemplate( void ) {
	top = bottom = NULL;
}

template< class type, int nextOffset >
void idStackTemplate<type,nextOffset>::Add( type *element ) {
	STACK_NEXT_PTR(element) = top;
	top = element;
	if ( !bottom ) {
		bottom = element;
	}
}

// more code.....


-----------------------------
C++ without virtual functions is not OO. Programming with classes but without dynamic binding is called "object based", but not "object oriented".
GeneralRe: What to replace macro in C/C++? Pin
Ryan Binns21-Nov-04 18:04
Ryan Binns21-Nov-04 18:04 
GeneralRe: What to replace macro in C/C++? Pin
Don Clugston21-Nov-04 19:11
Don Clugston21-Nov-04 19:11 
GeneralPostMessage Doesn't work with ALT Pin
Hany Grees Ayoub21-Nov-04 2:22
Hany Grees Ayoub21-Nov-04 2:22 
GeneralRe: PostMessage Doesn't work with ALT Pin
ThatsAlok21-Nov-04 17:50
ThatsAlok21-Nov-04 17:50 
GeneralRe: PostMessage Doesn't work with ALT Pin
22491721-Nov-04 22:14
22491721-Nov-04 22:14 
GeneralI got A Queistion about COM+ Pin
Rassul Yunussov21-Nov-04 0:46
Rassul Yunussov21-Nov-04 0:46 
GeneralSlider Control Pin
shijuck21-Nov-04 0:11
shijuck21-Nov-04 0:11 
Generalnew to dll files Pin
Swatgod20-Nov-04 21:11
Swatgod20-Nov-04 21:11 
GeneralRe: new to dll files Pin
Mike Danberg24-Nov-04 19:10
Mike Danberg24-Nov-04 19:10 
GeneralPrint Dialog appears sometimes Pin
Jo Fredrickson20-Nov-04 19:20
Jo Fredrickson20-Nov-04 19:20 
GeneralRe: Print Dialog appears sometimes Pin
Neville Franks20-Nov-04 22:55
Neville Franks20-Nov-04 22:55 
GeneralRe: Print Dialog appears sometimes Pin
Jörgen Sigvardsson21-Nov-04 2:43
Jörgen Sigvardsson21-Nov-04 2:43 
GeneralRe: Print Dialog appears sometimes Pin
Jo Fredrickson22-Nov-04 3:08
Jo Fredrickson22-Nov-04 3:08 
GeneralRe: WM_CTLCOLORBTN Pin
Michael Dunn20-Nov-04 19:16
sitebuilderMichael Dunn20-Nov-04 19:16 
GeneralRe: WM_CTLCOLORBTN Pin
Neville Franks20-Nov-04 22:58
Neville Franks20-Nov-04 22:58 
GeneralRe: WM_CTLCOLORBTN Pin
John R. Shaw21-Nov-04 6:10
John R. Shaw21-Nov-04 6:10 
GeneralRe: WM_CTLCOLORBTN Pin
Timothy Grabrian21-Nov-04 18:40
professionalTimothy Grabrian21-Nov-04 18:40 

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.