473,796 Members | 2,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3918
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***********@c a.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
6725
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 : .... Var RecordNb : integer ; .... {Command : function of Access}
3
627
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 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!
0
1216
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
2803
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 example, if A is a wrapper function around B). Thanks, Nimmi
13
2085
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 \ #warning "name is not a thread safe function" \ } while (0)
7
354
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 b){ return (a + b); } it can only deal with int + int or double + double however, I also want int + double, double + int so I come up with this idea template<class T , class U> T addition(T a, U b){ return (a+b); } this created a...
0
1838
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 Settings\Administrator.SLB_EUROPE\Desktop\norm ops 150607.xls" ' Select Asset & Portfolio Parameter sheet Sheets("Asset & Portfolio Parameter").Select ' Change the number of iterations Range("D7").Select
6
7449
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 extra external macro definition MTXROT_SIZE. Your comments are welcome on this code. Thank you for your time. /
7
4319
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, but i would like to know if there is any other smart way of doing the same? Thanks in advance!!!
2
2828
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
9530
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10182
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10017
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7552
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.