473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Function as macro parameter

Hello,

Is it bad practice to use a function as a parameter of a macro? Will
the compiler create a full copy of the function's machine code for
each invocation of the macro? Or does it create some type of pointer
to the function? Also is there any benefit from placing a return at
the end of a function which returns void? Thanks for any advice!
Nov 13 '05 #1
3 3883
Andrew wrote:
to the function? Also is there any benefit from placing a return at
the end of a function which returns void? Thanks for any advice!


Some people think the code looks better if there is return after each
function. (So they can see the end of a function right away.)

No other benefits than that.

Nov 13 '05 #2
an***********@ca.com (Andrew) wrote:
Hello,

Is it bad practice to use a function as a parameter of a macro? Will
the compiler create a full copy of the function's machine code for
each invocation of the macro? Or does it create some type of pointer
to the function?
A macro is handled by the C preprocessor. The C preprocessor knows
nothing about machine code or pointers - almost all it does is pure
text replacement (well, outside string literals, that is).
Also is there any benefit from placing a return at
the end of a function which returns void? Thanks for any advice!


You do not gain much in placing a return statement at the end of
a function returning void, execpt perhaps better readability -
it depends mostly on presonal preference.
--
6 * 9 = 42 (base 13)
Nov 13 '05 #3
Andrew wrote:
Hello,

Is it bad practice to use a function as a parameter of a macro? Will
the compiler create a full copy of the function's machine code for
each invocation of the macro? Or does it create some type of pointer
to the function? Also is there any benefit from placing a return at
the end of a function which returns void? Thanks for any advice!


Macros are not real functions in that they are completely removed before
your code even makes it to the compiler.

Calling a macro is identical to if you placed the body of the macro at
the macro call site, so no 'copy' of the function is ever made.

PS. Even passing a function as a parameter into a normal function
doesn't incur any copy overhead. Referencing a function by name simply
gives you a pointer to it, so you are essentially passing only a pointer
to the function.
--
Paul Richards

Sun Microsystems, Advanced Development
New Technology Researcher

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Clément Collin | last post by:
I working on a GIS project, with Access link which just need a little routine in VBA, but I haven't knowledges in VBA language. It's very simple, and it looks like that in a TPascal way : .......
3
by: Andrew | last post by:
Hello, Is it bad practice to use a function as a parameter of a macro? Will the compiler create a full copy of the function's machine code for each invocation of the macro? Or does it create...
0
by: Spiro Trikaliotis | last post by:
Hello, assume I define a macro like #if <somecondition> # define MACRO(_x, _y) _x #else # define MACRO(_x, _y) _y #endif
3
by: Nimmi Srivastav | last post by:
Consider two functions A and B, both of which accept a variable number of arguments (va_start, va-arg, va_end). Is there an easy way for arguments passed to A to be, in turn, passed to B? (For...
13
by: Anthony de Almeida Lopes | last post by:
Hello, I am wondering why it is not possible to have a function-like macro like the following: #define __nothread(name) do { \ #ifdef _PTHREAD_H ...
7
by: hopangtsun | last post by:
Hi all, I have encountered a problem on using the function template my goal is to add two numbers, which they can be int or double if I do this in this way template<class T> T addition(T a, T...
0
by: modularmix | last post by:
Does anyone know how to run the Excel Macro for two different spreadsheets in parallel. Here is the code that works sequentially. Workbooks.Open Filename:="C:\Documents and...
6
by: lovecreatesbea... | last post by:
Hello experts, I code an function to rotate a matrix by 90 degrees clockwise. The matrix can be in any size provided its length equals to width. The one minor limitation is that this requires an...
7
by: Rahul | last post by:
Hi Everyone, I have a function utility() which is a part of a library and i would like to know as to who is invoking the function. I could request that information as a parameter enumeration,...
2
by: Alex Vinokur | last post by:
Hi, Here is my program -------------- Program -------------- #define ADD(x,t) (x + t) template <typename T, int N> int foo() {
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.