473,809 Members | 2,826 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
12 1854
On Nov 15, 11:21*pm, Old Wolf <oldw...@inspir e.net.nzwrote:
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...) { }
All I get for it in 4.2.1 (the only version I have available
here) is:
varargs.cc:8: warning: control reaches end of non-void function
That's compiled with
g++ -std=c++98 -pedantic -ffor-scope -fno-gnu-keywords -foperator-
names -pipe -Wall -W -Wno-sign-compare -Wno-deprecated -Wno-non-
virtual-dtor -Wpointer-arith -Wno-unused -Wno-switch -Wno-missing-
braces -Wno-long-long -static-libgcc -ggdb3 -D_GLIBCXX_CONCE PT_CHECKS -
D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG _PEDANTIC
(my standard options).
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!
Not so much compilers. According to the first edition of _The
C++ Programming Language__ (1986), the comma isn't legal.
According to the C90 or the C++98 standard, it is optional.
I've never seen a compiler that didn't accept it either way, but
then, I don't think I'd have noticed if it didn't; I can't
remember ever actually using varargs in C++.

Since both are required by the standard, I wouldn't expect to
find support for both mentionned in the compiler documentation.

--
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 16 '08 #11
On Nov 16, 12:56*pm, James Kanze <james.ka...@gm ail.comwrote:
On Nov 15, 11:21*pm, Old Wolf <oldw...@inspir e.net.nzwrote:
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...) { }

All I get for it in 4.2.1 (the only version I have available
here) is:
* * varargs.cc:8: warning: control reaches end of non-void function
That's compiled with
* * g++ -std=c++98 -pedantic -ffor-scope -fno-gnu-keywords -foperator-
names -pipe -Wall -W -Wno-sign-compare -Wno-deprecated -Wno-non-
virtual-dtor -Wpointer-arith -Wno-unused -Wno-switch -Wno-missing-
braces -Wno-long-long -static-libgcc -ggdb3 -D_GLIBCXX_CONCE PT_CHECKS -
D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG _PEDANTIC
(my standard options).
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!

Not so much compilers. *According to the first edition of _The
C++ Programming Language__ (1986), the comma isn't legal.
According to the C90 or the C++98 standard, it is optional.
I've never seen a compiler that didn't accept it either way, but
then, I don't think I'd have noticed if it didn't; I can't
remember ever actually using varargs in C++.

Since both are required by the standard, I wouldn't expect to
find support for both mentionned in the compiler documentation.
I tried on another machine with gcc 4.0.1 .
g++ allows int foo(int x...) , gcc gives 'syntax error'.

I checked in C99 again and the grammar specification
doesn't seem to permit int foo(int x...) , the
relevant bits are:

direct-declarator:
direct-declarator ( parameter-type-list )
[snip]

parameter-type-list:
parameter-list
parameter-list , ...

Are you sure C90 allowed it?
Nov 16 '08 #12
On Nov 16, 11:53 pm, Old Wolf <oldw...@inspir e.net.nzwrote:
On Nov 16, 12:56 pm, James Kanze <james.ka...@gm ail.comwrote:
On Nov 15, 11:21 pm, Old Wolf <oldw...@inspir e.net.nzwrote:
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...) { }
All I get for it in 4.2.1 (the only version I have available
here) is:
varargs.cc:8: warning: control reaches end of non-void function
That's compiled with
g++ -std=c++98 -pedantic -ffor-scope -fno-gnu-keywords -foperator-
names -pipe -Wall -W -Wno-sign-compare -Wno-deprecated -Wno-non-
virtual-dtor -Wpointer-arith -Wno-unused -Wno-switch -Wno-missing-
braces -Wno-long-long -static-libgcc -ggdb3 -D_GLIBCXX_CONCE PT_CHECKS -
D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG _PEDANTIC
(my standard options).
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!
Not so much compilers. According to the first edition of
_The C++ Programming Language__ (1986), the comma isn't
legal. According to the C90 or the C++98 standard, it is
optional. I've never seen a compiler that didn't accept it
either way, but then, I don't think I'd have noticed if it
didn't; I can't remember ever actually using varargs in C++.
Since both are required by the standard, I wouldn't expect
to find support for both mentionned in the compiler
documentation.
I tried on another machine with gcc 4.0.1 .
g++ allows int foo(int x...) , gcc gives 'syntax error'.
I checked in C99 again and the grammar specification
doesn't seem to permit int foo(int x...) , the
relevant bits are:
direct-declarator:
direct-declarator ( parameter-type-list )
[snip]
parameter-type-list:
parameter-list
parameter-list , ...
Are you sure C90 allowed it?
I'll check tonight (my only copy of C90 is at home), if I
remember it, but if C99 doesn't allow it, it's highly unlikely
that C90 did; the C committee is even stricter about not
breaking existing code that is the C++ committee. (And I was
sure that C99 also allowed it, but I can't find what made me
think that in the 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 17 '08 #13

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

Similar topics

13
2472
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
2667
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
1650
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
11052
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
3157
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
1303
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
1907
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
1716
by: Ravi | last post by:
#define JOIN(s1,s2) printf("%s = %s %s = %s",#s1,s1,#s2,s2)
2
1301
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
9721
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
9600
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
10633
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
10375
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
9198
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...
0
5548
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...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
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.