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

is this a gcc extention or standard?

#define M(i, j) ({ ++i; j; })

int main(int argc, _TCHAR* argv[])
{
int i = 0;
int j = M(i, 3);
return 0;
}

the above code can compile with gcc, but can't compile with most other
compilers. is it a gcc extension, or standerd feature?

Apr 24 '06 #1
6 4117
steve yee said:
#define M(i, j) ({ ++i; j; })

int main(int argc, _TCHAR* argv[])
{
int i = 0;
int j = M(i, 3);
return 0;
}

the above code can compile with gcc, but can't compile with most other
compilers. is it a gcc extension, or standerd feature?


It's an extension. The macro syntax is non-standard, and the _TCHAR type is
non-standard.

If most compilers can't compile it, that's a pretty reasonable clue that
it's non-standard! (The whole point - or at least /a/ whole point - of
standard code is that you can use any compiler you like.)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Apr 24 '06 #2
In article <11**********************@i39g2000cwa.googlegroups .com>,
steve yee <yi******@gmail.com> wrote:
#define M(i, j) ({ ++i; j; })

int main(int argc, _TCHAR* argv[])
{
int i = 0;
int j = M(i, 3);
return 0;
}

the above code can compile with gcc, but can't compile with most other
compilers. is it a gcc extension, or standerd feature?


If most other compilers don't like it, then either it's a GCC extension
or the other compilers you're using are broken.

What does gcc -W -Wall -ansi -pedantic say?
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
The statement: "I am not stupid" on usenet is a challenge to all
readers to prove that you are (whether you actually are or not)
--Morris Dovey in comp.lang.c
Apr 24 '06 #3
Richard Heathfield wrote:
steve yee said:
#define M(i, j) ({ ++i; j; })

int main(int argc, _TCHAR* argv[])
{
int i = 0;
int j = M(i, 3);
return 0;
}

the above code can compile with gcc, but can't compile with most other
compilers. is it a gcc extension, or standerd feature?
It's an extension. The macro syntax is non-standard,


True, but there is a standard alternative...

#define M(i, j) (++(i), j)

Of course, I only _know_ this is a valid alternative because I know the
particular
gcc extension. [There are other forms on the extension which are not so
easy
to replicate in macro form.]
and the _TCHAR type is non-standard.
In the strictest sense, the identifier is standard in the sense that it
belongs
to a class of identifiers which are reserved for the implementation.

That said, it's use is obviously non-portable.
If most compilers can't compile it, that's a pretty reasonable clue that
it's non-standard!
More precisely, if most _conforming_ compilers (read... compilers
invoked in
conforming mode) can't compile it, it's a reasonable clue that it's
non-standard.
Many of the compilers I use will not compile trigraphs _unless_ they
are
invoked in conforming mode (or with trigraphs enabled.)
(The whole point - or at least /a/ whole point - of
standard code is that you can use any compiler you like.)


--
Peter

Apr 24 '06 #4
Peter Nilsson said:
Richard Heathfield wrote:
If most compilers can't compile it, that's a pretty reasonable clue that
it's non-standard!


More precisely, if most _conforming_ compilers (read... compilers
invoked in
conforming mode) can't compile it, it's a reasonable clue that it's
non-standard.


If it's not playing to C rules, it's not topical here in clc, so it is fair
within the context of this newsgroup to take it as read that it will be
invoked in conforming mode.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Apr 24 '06 #5
steve yee wrote:
#define M(i, j) ({ ++i; j; })

int main(int argc, _TCHAR* argv[])
{
int i = 0;
int j = M(i, 3);
return 0;
}

the above code can compile with gcc,
Really? gcc tells me:
3: error: expected declaration specifiers or '...' before '_TCHAR'
4: warning: 'main' takes only zero or two arguments
: In function 'main':
6: warning: ISO C forbids braced-groups within expressions
6: warning: unused variable 'j'
: At top level:
3: warning: unused parameter 'argc'
but can't compile with most other
compilers. is it a gcc extension, or standerd feature?


It is fairly common to expect a legal declaration of main, so gcc's
flagging as an error is not really a gcc extension.

Braced groups in expressions are illegal in standard C, so gcc's
diagnostic is not really a gcc extension.

Helpful messages about unused variables are not mandated by the
standard, so I guess you could call those gcc extensions.
Apr 24 '06 #6
sorry, for gcc, the code should be:

#define M(i, j) ({ ++i; j; })

int main(int argc, char* argv[])
{
int i = 0;
int j = M(i, 3);
return j;
}
What does gcc -W -Wall -ansi -pedantic say?


bash-2.03$ gcc -W -Wall -ansi -pedantic t.c
t.c: In function 'main':
t.c:7: warning: ISO C forbids braced-groups within expressions
t.c:9: warning: control reaches end of non-void function
bash-2.03$ gcc -v
Using built-in specs.
Target: sparc-sun-solaris2.8
Configured with: ../src-gcc/configure --prefix=/opt/gcc
--with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld
--enable-languages=c,c++
Thread model: posix
gcc version 4.1.1 20060421 (prerelease)

Apr 24 '06 #7

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

Similar topics

2
by: Jesper Olsen | last post by:
I have a python extention implemented in C/C++ - the extention itself is internally implemented in C++, but the interface is pure C, so that it can easily be called from a python C-wrapper. The...
0
by: Atul Kshirsagar | last post by:
I am embedding python in my C++ application. I am using Python *2.3.2* with a C++ extention DLL in multi-threaded environment. I am using SWIG-1.3.19 to generate C++ to Python interface. Now to...
1
by: Carl Ogawa | last post by:
How do I make .cgi extention work? I installed ActivePerl 5.8. My CGI scripts work fine with .PL extention but not .CGI extention although I associated CGI extention as exactly same as PL...
1
by: MFA | last post by:
Hi all I have installed Front page server Extention on IIS 5.0 it was working fine. I was able to load project from Visual Interdav and doing well. Yesterday I installed a security update from...
3
by: Tuvas | last post by:
I am currently writing an extention module that needs to recieve a list of characters that might vary in size from 0 to 8. This is written as a list of characters rather than a string because it's...
1
by: godfather96 | last post by:
I am using a web control called eXml which is an extention to ms xml web control which supports xslt 2.0 when trying to group elements i receive the following error: group-by is not a valid...
5
by: Krustov | last post by:
I have the following list of image files . When searching the latest (numbered file) in this particular case its background_4.*** and its a .jpg file - but - the latest file in the list could...
10
by: shaiful | last post by:
Hi all I have a problem with extention of file. such as: Dim s, s1 As String s = "Test.doc" i want get the value of s is in s1 as "Test.txt" such as : s1 = "Test.txt" so, how i can get...
4
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
I'm do meore and more with extention methods, totally cool. They are making life much easier for IU developers. I'm trying to add a return type of struct to a asp.net DropDownList of type struct....
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
0
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,...

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.