473,857 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

meaning of define

What is meaning of the following define:-

#define x(argl...) x1(##argl)

Aug 31 '06 #1
17 2787
ni**********@gm ail.com wrote:
What is meaning of the following define:-

#define x(argl...) x1(##argl)
I don't think variadic macros are allowed in C++, so the ... part is
not standard. The ## is the token pasting operator. It pastes the token
that you pass as an argument. For example the macro

#define var(n) var##n

would cause 'var(3)' to be expanded to 'var3'.

Regards,
Bart.

Aug 31 '06 #2

Bart wrote:
ni**********@gm ail.com wrote:
What is meaning of the following define:-

#define x(argl...) x1(##argl)

I don't think variadic macros are allowed in C++, so the ... part is
not standard. The ## is the token pasting operator. It pastes the token
that you pass as an argument. For example the macro

#define var(n) var##n

would cause 'var(3)' to be expanded to 'var3'.

Regards,
Bart.
I have tried this and this compiles on c++ compiler but if you try
something like
#define x(argl,...) x1(##arl)
or
#define x(...) x1(##)
compiler throws error. So can you explain how this is being expanded? I
think normal syntax of variable number of argument is foo(some arg,...)
or simply foo(...).
Thanks,
Niraj

Aug 31 '06 #3

## operator in C++ is used inside macros to concatenate two tokens for
example :-

#include <iostream>
using namespace std;
#define func(x) x##out<<"Hello! "<<endl

int main(){
func(c);
system("pause") ;
}

Above programme will print Hello! on screen.
I have tried this and this compiles on c++ compiler but if you try
something like
#define x(argl,...) x1(##arl)
or
#define x(...) x1(##)
compiler throws error. So can you explain how this is being expanded? I
think normal syntax of variable number of argument is foo(some arg,...)
or simply foo(...).
Thanks,
Niraj

Aug 31 '06 #4
flamexx7 posted:
## operator in C++ is used inside macros to concatenate two tokens

It's nothing to do with the C++ language itself -- it's purely to do with the
preprocessor.

--

Frederick Gotham
Aug 31 '06 #5
ni**********@gm ail.com wrote:
<snip>
I have tried this and this compiles on c++ compiler
That your compiler has accepted it doesn't mean that it's standard C++.
IIRC the C99 standard allows variadic macros, and some compilers have
accepted them prior to that, but that doesn't make it legal C++.

<snip>
I think normal syntax of variable number of argument is foo(some arg,...)
or simply foo(...).
No, the second foo is not valid. Functions with a variable number of
arguments must have at least one formal argument for the va_start macro
to work. Again, some compilers have extensions that allow foo(...), but
that's not standard C++.

Regards,
Bart.

Aug 31 '06 #6
Frederick Gotham wrote:
flamexx7 posted:
## operator in C++ is used inside macros to concatenate two tokens

It's nothing to do with the C++ language itself -- it's purely to do with the
preprocessor.
Well, the standard which defines the C++ language also defines the
preprocessor, so from a purely formal point of view the preprocessor IS
part of the language. The reasons for which people think of the
preprocessor as a separate entity from the language are mostly
historical and practical.

Regards,
Bart.

Aug 31 '06 #7
flamexx7 wrote:
>
## operator in C++ is used inside macros to concatenate two tokens


Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.c om/c++-faq-lite/how-to-post.html>


Brian
Aug 31 '06 #8
Frederick Gotham wrote:
flamexx7 posted:
>## operator in C++ is used inside macros to concatenate two tokens


It's nothing to do with the C++ language itself -- it's purely to do with
the preprocessor.
The preprocessor is part of the C++ language.

Sep 1 '06 #9
"Frederick Gotham" wrote:
Rolf Magnus posted:
>>It's nothing to do with the C++ language itself -- it's purely to do
with
the preprocessor.

The preprocessor is part of the C++ language.


Yes, but the _actual_ C++ compiler doesn't know anything about #define...
all
of that has been stripped away in the preprocessor phase.

--

Frederick Gotham
Couldn't you just admit that you shouldn't have made your initial post and
let it go at that? It is not necessary that you respond to each and every
message. AFAIK the preprocessor is a *conceptual* phase. Conceptual means
"not real".
Sep 1 '06 #10

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

Similar topics

16
23830
by: godfather2 | last post by:
this should be an easy one ... what is the meaning of "1u", for instance: #define DUMMY (1U<<31) as opposed to just: #define DUMMY (1<<31)
6
1852
by: Muralidhar | last post by:
Hi all, I saw in one function that its return type was written as PACKED...I wasnt sure what that would mean. Any pointers on this? Also, what is the significance of specifically mentioning the LOCAL to a function definition when it will be a local function without the access of its declaration? Thanks
19
3877
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the storage-class specifier will have "extern" as the default storage-class specifier. My (little) C experience tells me that an object with "extern" is to let the linker knows that the object is referencing the object defined in somewhere, and this "somewhere" object does not have the storage-class specifier...
9
28702
by: Qiao Jian | last post by:
I am new to c. Today I just read an h file within which there is statements: #ifndef _RANDOM_H #define _RANDOM_H So what is the meaning or purpose of this statement? When should I use such statement in my own program? Thank you so much!
1
2173
by: DaVinci | last post by:
I had thinked about the implements of variable argument for a long time. But I only know a little about it on the following macro. Could you please explain it for me? more detail.Thanks very much. typedef char *va_list; 275 #endif /* _VALIST */ 276 277 /*
15
2821
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs. For example: f(3) f(3, )
4
2214
by: _mario.lat | last post by:
for struct: struct in6_addr { uint8_t s6_addr; }; is provided a costant: #define IN6ADDR_LOOPBACK_INIT {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}} what does means {{{, and }}}?
43
17252
by: emyl | last post by:
Hi all, here's an elementary question. Assume I have declared two variables, char *a, **b; I can then give a value to a like a="hello world";
4
1919
by: StdNewer | last post by:
#ifndef OF /* function prototypes */ # ifdef STDC # define OF(args) args # else # define OF(args) () # endif #endif void func OF( args );
0
9923
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10711
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10807
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
10394
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
9549
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 projectplanning, coding, testing, and deploymentwithout 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
7939
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
7104
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
4592
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
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.