Subject: RE: [hackers-il] GCC's statement expressions

From: Arik Baratz <[email-masked]>
Date: Tue, 8 Jan 2002 13:51:58 +0200

Did it fail on other compilers? It seems pretty standard to me.

-- Arik

-----Original Message-----
From: Shlomi Fish [mailto:[email-masked]]
Sent: Tue, January 08, 2002 1:45 PM
To: Hackers-IL
Subject: [hackers-il] GCC's statement expressions

The following snippet compiles with gcc:

#include <stdio.h>

int main()
{
    int sum;

    sum = 100;

    sum += ({ int s = 0; int a; for(a=0;a<10;a++) { s+=a; } s;});

    printf("%i\n", sum);

    return 0;
}

It seems the ({ ... }) are the equivalent of do { } or eval { } in perl. I
always wanted such a feature in C, so it's nice to know gcc has it. Too
bad it is not standard.

Regards,

	Shlomi Fish

----------------------------------------------------------------------
Shlomi Fish        [email-masked]
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

"Let's suppose you have a table with 2^n cups..."
"Wait a second - is n a natural number?"

To unsubscribe from this group, send an email to:
[email-masked]

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

******************************************************************
This mail message was scanned by Vidius Port Authority 
(Enterprise Edition) for unauthorized confidential and 
proprietary information.

http://www.vidius.com
******************************************************************

---

From: Oleg Goldshmidt <[email-masked]>
Date: 08 Jan 2002 15:42:53 +0200

> Did it fail on other compilers? It seems pretty standard to me.

It is not standard - you cannot have blocks inside a statement in
ANSI C.

-- 
Oleg Goldshmidt | [email-masked] 
"If it ain't broken, it has not got enough features yet."