M
madhawi
Is it better to use a macro or a function?
madhawi said:Is it better to use a macro or a function?
madhawi said:Is it better to use a macro or a function?
madhawi said:Is it better to use a macro or a function?
madhawi said:Is it better to use a macro or a function?
Is it better to use a macro or a function?
[/QUOTE]Is it better to use a macro or a function?
Is it better to use a spoon or a saw?
Tejas said:If functions are relatively short, using a macro is better since it
avoids overhead of stack frame allocation ( saving stack pointer of
caller,saving return address of the instruction in caller function on
the stack frame etc).
If functions are relatively short, using a macro is better since it
avoids overhead of stack frame allocation ( saving stack pointer of
caller,saving return address of the instruction in caller function on
the stack frame etc).
However if the functions are long, using macros can be debugging nightmare.
madhawi said:Is it better to use a macro or a function?
Is it better to use a spoon or a saw?
Chris said:If the functions are relatively short, calling them may well not
involve any stack frame allocation /at all/. The overhead may be
roughly two instructions -- call & return. Or, of course, the compiler
may inline the function completely.
Flash said:Tejas Kokje wrote, On 06/06/07 20:28:
Apart from when it does not. I'm sure it's over 10 years since I read a
compiler manual which talked about it inlining small functions.
1st rule of optimisation, don't do it. Whilst you think using a macro is
for a small function is better due to efficiency you are not ready for
the 2nd rule.
The same applies to small functions.
Tejas said:I didn't get your first comment. If you don't allocate stack frame,
where are you going to store return address when you do "call & return" ?
Compiler *may* inline the function. But it is not obligated to do so.
The rules used to select functions for inline are documented with yourTejas said:Are there any set of rules (even for a specific compiler) which says
that small functions with x,y,z properties will always be inlined ? It
would be interesting to know those
I didn't get your first comment. If you don't allocate stack frame,
where are you going to store return address when you do "call & return" ?
Compiler *may* inline the function. But it is not obligated to do so.
Are there any set of rules (even for a specific compiler) which says
that small functions with x,y,z properties will always be inlined ? It
would be interesting to know those
1st rule of optimisation, don't do it. Whilst you think using a macro
is for a small function is better due to efficiency you are not ready
for the 2nd rule.
The same applies to small functions.
With functions you have symbols in symbol table and you can use symbolic
debugger to debug problems.
However, with long macro functions, you don't have symbols in symbol table.
Hence for long functions, I would "prefer the compiler to the
preprocessor" [Scot Myers, Effective C++].
Chris said:In the specific case I am thinking of, in the return address register,
R14, which is where the call instruction puts it.
I didn't get your first comment. If you don't allocate stack frame,
where are you going to store return address when you do "call & return" ?
Compiler *may* inline the function. But it is not obligated to do so.
I may be going off topic, but which architecture has R14 register ?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.