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

empty parameterized macro


Hello,

I would like to know whether there is any difference between
the macro

#define FOO

and the parameterized macro taking no parameters

#define FOO()

What is the purpose of the empty parameter list in the latter?

Thanks,

JG

Nov 27 '06 #1
3 1911
John Goche writes:
I would like to know whether there is any difference between
the macro

#define FOO

and the parameterized macro taking no parameters

#define FOO()
They are called differently. The first is called as just FOO, the
second is called as FOO(). With the second, 'FOO' without () after it
is not expanded at all. If you want to define a constant, you'll
typically define FOO. If you define something which evaluates at
run-time, it looks more informative if you define FOO().

#define FOO one
#define BAR() two
#define BAZ BAR
Now the code
FOO w BAR x BAR() y BAZ() z
expands to
one w BAR x two y two z

--
Hallvard
Nov 27 '06 #2

Hallvard B Furuseth wrote:
John Goche writes:
I would like to know whether there is any difference between
the macro

#define FOO

and the parameterized macro taking no parameters

#define FOO()
Is that even allowed under c89?

If so, chapter and verse please.

--
aegis

Nov 28 '06 #3
aegis writes:
>Hallvard B Furuseth wrote:
>>John Goche writes:
>>I would like to know whether there is any difference between
the macro
#define FOO
and the parameterized macro taking no parameters
#define FOO()

Is that even allowed under c89?
If so, chapter and verse please.
Huh? Why not? Ever head of systems where getchar() is a macro?

Look up chapter and verse yourself if you think it's not allowed.
The grammar is something like
# define identifier(identifier-list<opt>) replacement-list new-line
Note the <opt(optional).

--
Hallvard
Nov 28 '06 #4

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

Similar topics

25
by: Sabyasachi Basu | last post by:
While trying to port some stuff from Unix to Windows, I encountered a strange behaviour of function macros with empty arguments. Here is a small snippet which illustrates the problem: #include...
2
by: FizzBin | last post by:
We are writing a C application that is using ODBC to insert records into a database. We have a NOT NULL column that can legitimately have an empty value, i.e. we know the value and it is empty...
1
by: gary b | last post by:
Hello When I use a PreparedStatement (in jdbc) with the following query: SELECT store_groups_id FROM store_groups WHERE store_groups_id IS NOT NULL AND type = ? ORDER BY group_name
10
by: Chuck | last post by:
I have a macro that saves data to an A: drive. If the drive is empty and I run the macro, the drive clicks a few times, and a message comes up saying "the file already exists, do I want to over...
8
by: deko | last post by:
I'm trying to open a Recordset based on a parameterized query. I'm kind of new to parameterized queries, so I'm sure I'm missing something simple. Set qdfs = db.QueryDefs Set qdf =...
1
by: satya.mahesh | last post by:
Hi All, I am working on a problem which "eliminates blank lines in export (between headings and when a heading is empty)". I want a macro which will do this job for me. For e.g: Heading1 ...
15
by: Urs Thuermann | last post by:
I want to write a macro that produces debug output and has a variable number of arguments, so that I can use like this: int i; char *s; DBG("simple message\n"); DBG("message with an int...
2
by: talkaboutquality | last post by:
Need to define a macro as, say, #ifdef NEED_FUNCTION foo(x) #else #endif
9
by: Two-Horned Unicorn | last post by:
The following code compiles and works as expected when compiled with gcc. /* empty-args.c */ #include <stdio.h> #define foo(x,y) puts("bar: x=\"" #x "\"; y=\"" #y "\"") #define bar(x) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.