By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

macro and function

P: n/a
HI.In what circumstances we should use a macro and when we should use a
function? If we use macro then will the size of the executable
increase?Thanks for help.

Eric

Oct 19 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
di**********@yahoo.com wrote:
HI.In what circumstances we should use a macro and when we should use a
function?
Is there anything wrong with the thread started yesterday and still very
much active, first post <eh**********@usenet02.sei.cmu.edu>, subject
inline functions vs. macros?

Richard
Oct 19 '06 #2

P: n/a
di**********@yahoo.com said:
HI.In what circumstances we should use a macro and when we should use a
function?
If in doubt, use a function.
If we use macro then will the size of the executable
increase?
Probably. It depends on the macro, how you use it, how often you use it, and
how astounding your compiler is.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 19 '06 #3

P: n/a
In article <11**********************@b28g2000cwb.googlegroups .com>,
<di**********@yahoo.comwrote:
>HI.In what circumstances we should use a macro and when we should use a
function?
macro: if you need the result at compile time, or if you
need to "stringize" something, or if you need to splice
together parts of a name to arrive at a new preprocessor macro name
whose value is required, or if you need to construct new syntaxes
or if you need a form that needs to work over multiple types

>If we use macro then will the size of the executable
increase?
That's an implementation issue, and might depend on the precise
nature of the macro and upon the contexts it is used in or upon
the number of times it is used. Sometimes using macros might result
in smaller executables and sometimes it might result in larger executables.

Talking about the size of an executable is usually not particularily
useful. An executable might include debugging information, might
include library linkage information, might bother to "merge"
constant literals, might "unroll" loops for optimization, might
use a longer sequence of instructions rather than a shorter sequence
if the longer sequence would be more efficient, might contain
the same code compiled for multiple architectures, and so on.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Oct 19 '06 #4

P: n/a

"Richard Bos" <rl*@hoekstra-uitgeverij.nlwrote in message
news:45****************@news.xs4all.nl...
di**********@yahoo.com wrote:
>HI.In what circumstances we should use a macro and when we should use a
function?

Is there anything wrong with the thread started yesterday and still very
much active, first post <eh**********@usenet02.sei.cmu.edu>, subject
inline functions vs. macros?

Richard
The posters are probably taking the same class.
The second one probably didn't bother to check previous threads.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
Oct 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.