Click here to Skip to main content
15,914,409 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Memory Manager Pin
harold aptroot8-Jul-09 8:12
harold aptroot8-Jul-09 8:12 
Questioninline or macro Pin
Be programmer8-Jul-09 6:36
Be programmer8-Jul-09 6:36 
AnswerRe: inline or macro Pin
Michael Schubert8-Jul-09 6:46
Michael Schubert8-Jul-09 6:46 
GeneralRe: inline or macro Pin
George L. Jackson8-Jul-09 6:59
George L. Jackson8-Jul-09 6:59 
GeneralRe: inline or macro Pin
PJ Arends8-Jul-09 9:12
professionalPJ Arends8-Jul-09 9:12 
JokeRe: inline or macro Pin
David Crow8-Jul-09 7:07
David Crow8-Jul-09 7:07 
JokeRe: inline or macro Pin
Roger Stoltz8-Jul-09 8:11
Roger Stoltz8-Jul-09 8:11 
AnswerRe: inline or macro Pin
Stuart Dootson8-Jul-09 7:14
professionalStuart Dootson8-Jul-09 7:14 
Be programmer wrote:
inline or macro


There are very, very, very, very few reasons to ever consider using a macro rather than an inline function. In fact, your question is a subset of the second item in Scott Meyer's Effective C++ (one of the C++ textbooks you really want to read):

Item 2: Prefer consts, enums, and inlines to #defines


The reasons?

  1. Macros live outside the type system
  2. Macros pollute all namespaces
  3. There can be unexpected outcomes from macros. Consider the following macro function and it's use:
    #define CALL_WITH_MAX(a, b) f((a) > (b) ? (a) : (b))
    
    CALL_WITH_MAX(++a, b);          // a is incremented twice
    CALL_WITH_MAX(++a, b+10);       // a is incremented once


    Can you predict that reliably? Nope, thought not.


So, to paraphrase...just don't ever use a macro instead of an inline function.

Don't try to micro-optimise before you know what the slow things are...

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

AnswerRe: inline or macro Pin
KellyR8-Jul-09 7:36
KellyR8-Jul-09 7:36 
GeneralRe: inline or macro Pin
Michael Schubert8-Jul-09 10:48
Michael Schubert8-Jul-09 10:48 
QuestionRe: inline or macro Pin
Rajesh R Subramanian8-Jul-09 19:35
professionalRajesh R Subramanian8-Jul-09 19:35 
AnswerRe: inline or macro Pin
Michael Schubert8-Jul-09 20:59
Michael Schubert8-Jul-09 20:59 
GeneralRe: inline or macro Pin
Rajesh R Subramanian8-Jul-09 21:55
professionalRajesh R Subramanian8-Jul-09 21:55 
AnswerRe: inline or macro Pin
CPallini8-Jul-09 21:09
mveCPallini8-Jul-09 21:09 
GeneralRe: inline or macro Pin
Rajesh R Subramanian8-Jul-09 21:57
professionalRajesh R Subramanian8-Jul-09 21:57 
AnswerRe: inline or macro Pin
Maximilien8-Jul-09 8:27
Maximilien8-Jul-09 8:27 
GeneralRe: inline or macro Pin
CPallini8-Jul-09 21:04
mveCPallini8-Jul-09 21:04 
Questiondifference b/w iterators and indexing for STL Pin
hawk23reddy8-Jul-09 6:32
hawk23reddy8-Jul-09 6:32 
AnswerRe: difference b/w iterators and indexing for STL Pin
minkowski8-Jul-09 6:57
minkowski8-Jul-09 6:57 
AnswerRe: difference b/w iterators and indexing for STL Pin
Stuart Dootson8-Jul-09 7:04
professionalStuart Dootson8-Jul-09 7:04 
QuestionHow to use gotoxy().....? Pin
Razanust8-Jul-09 6:08
Razanust8-Jul-09 6:08 
AnswerRe: How to use gotoxy().....? Pin
Michael Schubert8-Jul-09 6:58
Michael Schubert8-Jul-09 6:58 
AnswerRe: How to use gotoxy().....? Pin
Jijo.Raj8-Jul-09 7:20
Jijo.Raj8-Jul-09 7:20 
Questionnewbie to multi threading Pin
minkowski8-Jul-09 5:45
minkowski8-Jul-09 5:45 
AnswerRe: newbie to multi threading Pin
Stuart Dootson8-Jul-09 6:54
professionalStuart Dootson8-Jul-09 6:54 

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.