473,799 Members | 2,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Could anybody explain this macro for me?

#define D(y...) (const int []) {y}

My understand is that D is taking in a various length parameter y
which is an array of const int. Am I right?

Thanks.
Nov 12 '08 #1
12 1852
On Nov 13, 12:46*pm, "webinfin...@gm ail.com" <webinfin...@gm ail.com>
wrote:
#define D(y...) (const int []) {y}

My understand is that D is taking in a various length parameter y
which is an array of const int. Am I right?
This is a syntax error. Are you sure you transcribed
it correctly?
Nov 13 '08 #2
Old Wolf wrote:
On Nov 13, 12:46 pm, "webinfin...@gm ail.com" <webinfin...@gm ail.com>
wrote:
>#define D(y...) (const int []) {y}

My understand is that D is taking in a various length parameter y
which is an array of const int. Am I right?

This is a syntax error. Are you sure you transcribed
it correctly?
To me it looks like a variadic macro from the newer C standard, not
yet in the C++ standard.
Nov 13 '08 #3
we*********@gma il.com wrote:
#define D(y...) (const int []) {y}

My understand is that D is taking in a various length parameter y
which is an array of const int. Am I right?
Try c.l.c, this looks like C99.

--
Ian Collins
Nov 13 '08 #4
On Nov 12, 7:06*pm, Ian Collins <ian-n...@hotmail.co mwrote:
webinfin...@gma il.com wrote:
#define D(y...) (const int []) {y}
My understand is that D is taking in a various length parameter y
which is an array of const int. Am I right?

Try c.l.c, this looks like C99.

--
Ian Collins
That's not any C99 syntax I know of, either. C99 provides __VA_ARG__
for variadic macros.

Nov 13 '08 #5
On Nov 13, 1:28 am, Juha Nieminen <nos...@thanks. invalidwrote:
Old Wolf wrote:
On Nov 13, 12:46 pm, "webinfin...@gm ail.com" <webinfin...@gm ail.com>
wrote:
#define D(y...) (const int []) {y}
My understand is that D is taking in a various length
parameter y which is an array of const int. Am I right?
This is a syntax error. Are you sure you transcribed it
correctly?
To me it looks like a variadic macro from the newer C
standard, not yet in the C++ standard.
There are actually two things in the above which cause syntax
errors in current C++. The first is that it is a variadic
macro, which is legal in C99 and will be legal in the next
version of C++. The second is that when expanded, this results
in a compound literal. Again, C99, but not current C++; in this
case, I know that the next version will extend the
initialization syntax, but I'm not sure whether the extension
will look exactly like a compound literal in C or not.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Nov 13 '08 #6
On Nov 13, 11:04*pm, James Kanze <james.ka...@gm ail.comwrote:
On Nov 13, 1:28 am, Juha Nieminen <nos...@thanks. invalidwrote:
Old Wolf wrote:
On Nov 13, 12:46 pm, "webinfin...@gm ail.com" <webinfin...@gm ail.com>
>
>#define D(y...) (const int []) {y}

There are actually two things in the above which cause syntax
errors in current C++. *The first is that it is a variadic
macro, which is legal in C99 and will be legal in the next
version of C++. *
Variadic macros in C99 look like:

#define D(y, ...)

i.e. the ellipsis is separated from the other
arguments by a comma (with optional whitespace).

The ellipsis directly following the argument
name, isn't in any C standard. (Another poster
suggests that it's a GCC extension).

Nov 15 '08 #7
On Nov 15, 5:04*am, Old Wolf <oldw...@inspir e.net.nzwrote:
On Nov 13, 11:04*pm, James Kanze <james.ka...@gm ail.comwrote:
On Nov 13, 1:28 am, Juha Nieminen <nos...@thanks. invalidwrote:
Old Wolf wrote:
On Nov 13, 12:46 pm, "webinfin...@gm ail.com" <webinfin...@gm ail.com>
#define D(y...) (const int []) {y}
There are actually two things in the above which cause syntax
errors in current C++. *The first is that it is a variadic
macro, which is legal in C99 and will be legal in the next
version of C++. *
Variadic macros in C99 look like:
* #define D(y, ...)
i.e. the ellipsis is separated from the other
arguments by a comma (with optional whitespace).
So I see. I wonder why they didn't support the form without the
comma, as they do in function declarations. Shocking lack of
orthogonality.

(Historically, the comma wasn't allowed in function
declarations; the syntax was exactly that of a natural language,
where you would never write "a, b, ..." but always "a, b...".
When C adopted this syntax from C++, the C committee decided to
allow the syntax with the comma as well; I'm not sure what their
reasoning was, but I also find it more appealing, separating the
.... from the preceding argument. But not enough more appealing
to have justified changing or extending the existing
specification; if it were a new invention, I'd define it with
the comma, but since it wasn't, and isn't, I don't think that
there was, or is, sufficient justification to add the form with
the comma.)
The ellipsis directly following the argument name, isn't in
any C standard. (Another poster suggests that it's a GCC
extension).
Might be. I would certainly expect that most implementations
supporting vararg templates support it (except maybe in their
strictest modes), much like they support a final comma in an
enum list. There is absolutely no reason not to be orthogonal
here (and I would consider this a defect in the C standard).

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Nov 15 '08 #8
Old Wolf wrote:
The ellipsis directly following the argument
name, isn't in any C standard. (Another poster
suggests that it's a GCC extension).
Straight from the horse's mouth:

http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
Nov 15 '08 #9
On Nov 15, 11:00*pm, James Kanze <james.ka...@gm ail.comwrote:
On Nov 15, 5:04*am, Old Wolf <oldw...@inspir e.net.nzwrote:
The ellipsis directly following the argument name, isn't in
any C standard. (Another poster suggests that it's a GCC
extension).

Might be. *I would certainly expect that most implementations
supporting vararg templates support it (except maybe in their
strictest modes), much like they support a final comma in an
enum list. *There is absolutely no reason not to be orthogonal
here (and I would consider this a defect in the C standard).
Well, the gcc-3.4.4 I have here, running in
standard mode, just gives 'parse error' for:

int foo(int x...) { }

I've never encountered this form (without the
comma), and I usually do read the list of
extensions in compiler documentation when using
a new compiler. Obviously you have more experience
with compilers than I do though!
Nov 15 '08 #10

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

Similar topics

13
2471
by: C++fan | last post by:
The following code is for list operation. But I can not understand. Could anyone explain the code for me? /* * List definitions. */ #define LIST_HEAD(name, type) struct name { type *lh_first; /* first element */
10
2666
by: Steven T. Hatton | last post by:
Stroustrup says this: http://www.research.att.com/~bs/bs_faq2.html#macro "So, what's wrong with using macros?" "And yes, I do know that there are things known as macros that doesn't suffer the problems of C/C++ preprocessor macros. However, I have no
21
1647
by: Gactimus | last post by:
Can anyone explain what the lines with the '*' by them do? ----------- #ifndef _COUNTER_H #define _COUNTER_H #include <iostream> using namespace std; class Counter
5
11050
by: Tim Eliot | last post by:
Just wondering if anyone has hit the following issue and how you might have sorted it out. I am using the command: DoCmd.TransferText acExportMerge, , stDataSource, stFileName, True after setting stDataSource and stFileName to the desired values. Most of the time it works, but occasionally, typically as code changes are being made to the module, the following message appears:
6
3156
by: Affan Syed | last post by:
I am not able to figure out exactly what this macro is doing. Can one of the gurus around here decipher this? #define sei() __asm__ __volatile__ ("sei" ::) PS: It is from the avr-libc interrupt.h and it should set a partilcular interrrupt. Thanks.
0
1301
by: skumar | last post by:
I am trying to open Word from ASP.net. But when i try to open the word document i am getting "Could not open Macro Storage" Can anybody give me a .NET way of making this work.
11
1906
by: kartheeknagasuri | last post by:
my friend gave this code to me..... it is working fine....how come? please explain me if u can understand..... #include <stdio.h> #include <conio.h> #define _(__,___)\ ___##__
4
1715
by: Ravi | last post by:
#define JOIN(s1,s2) printf("%s = %s %s = %s",#s1,s1,#s2,s2)
2
1300
by: TYF | last post by:
hi, can any one explain me what this little macro is doing? #define pos_of(h, f) ((short int) &((h *) 0)->f) h is a struct f is a member of it i have no clue, i only know it has something to do with the position.
0
9686
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10475
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
10222
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
10026
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...
1
7564
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
6805
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();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
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.