By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,335 Members | 2,718 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,335 IT Pros & Developers. It's quick & easy.

is this a gcc extention or standard?

P: n/a
#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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.