473,322 Members | 1,562 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,322 software developers and data experts.

macros with parameters

The following code compiles on 2 compilers here:

#define X(a) ((a)+10)

int main(void)
{
int X = 2;

return 0;
}

but if X is defined as #define X (2)
then this code doesnt compile anymore?

Is that according to standard ?
Jan 13 '07 #1
2 1707
Serve Laurijssen writes:
The following code compiles on 2 compilers here:

#define X(a) ((a)+10)

int main(void)
{
int X = 2;

return 0;
}
Yup... the X macro takes one argument, but since you didn't give
an argument it can't be the macro, so it is not expanded.
but if X is defined as #define X (2)
then this code doesnt compile anymore?
With a space after the macro name, it is an "object-like" macro
which does not take any parens. So your code becomes

int (2) = 2;
Is that according to standard ?
Yup.

--
Hallvard
Jan 13 '07 #2
Serve Laurijssen said:
The following code compiles on 2 compilers here:

#define X(a) ((a)+10)

int main(void)
{
int X = 2;

return 0;
}

but if X is defined as #define X (2)
then this code doesnt compile anymore?

Is that according to standard ?
Yes. #define X(a) ((a)+10) defines a function-like macro. To invoke a
function-like macro, you'd have to say something like X(arg), complete with
parenthesised argument - not just X on its own. So your example program
simply defines an int called X, which is obviously legal; it doesn't invoke
your macro at all.

#define X (2) doesn't define a function-like macro. If you were to change
your program in this way, it would expand to:

int main(void)
{
int (2) = 2;

return 0;
}

which is obviously illegal.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 13 '07 #3

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

Similar topics

2
by: Boris Sargos | last post by:
Hi, I wrote the Matrix class suggested by Stroustrup in his reference book, and in this aim, wrote too the following member function, which returns the ith row of the Matrix : ...
6
by: Reg | last post by:
At present I'm running a number of macros with a schedular on my computer to update and maintain databases within our network. All my backends contain the tables that the macros update. But all the...
0
by: jpodesta | last post by:
Hello- I am fairly new to MS Access and would like to use some macros in .xls in an Access Module. I have tried to do this on my own but failed to make it work. I have included the xls macros...
5
by: Andrew Arro | last post by:
first of all i would like to thank Alexander Bartolich and Richard Heathfield for answering my "macros question" #1 another macros question now: how could i define a macros with variable...
4
by: Augustus S.F.X Van Dusen | last post by:
I have recently come across the following construction: #define P_VAR(output, string, args...) \ fprintf (output, "This is "string"\n", ##args) which can be invoked as follows: int x = 1,...
1
by: avasilev | last post by:
Hi all, I am upgrading a kind of small logging framework. Until now, the interface for logging messages takes only a format string, and a variable argument list (in a similiar way as printf())....
11
by: San | last post by:
hi there, I am new to c++ and tryig to learn the basics of the c++ concepts. While I was reading the templates, I realize that the templates are a syntax that the compilar expands pased upon the...
27
by: Cephalobus_alienus | last post by:
Hello, I know that macros are evil, but I recently came across a problem that I couldn't figure out how to solve with templates. I wanted to create a set of singleton event objects, and wrote...
20
by: copx | last post by:
Is it true that C macros are unsafe when combined with side effects even if they are "clean" e.g. could foo_macro(++c); execute "++c" multiple times even if foo_macro is "clean"? I have always...
5
by: Salad | last post by:
If I click on the Macros button in the database window there is 1 macro that exists...AutoExec. If I click on the Modules button and enter the VB Editor window there's the menu option Tools. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.