standard C? -> int b = ({int a; a = 5; a;})

J

John Reye

Hello,

is it standard C... that the value obtained when evaluating a block is
the last expression in the block??

Example:
int b = ( {
int a;
a = 5;
a;
}
);



Thanks.
 
J

jacob navia

Le 14/06/12 10:23, John Reye a écrit :
Hello,

is it standard C... that the value obtained when evaluating a block is
the last expression in the block??

Example:
int b = ( {
int a;
a = 5;
a;
}
);



Thanks.

No, this is not standard c but an extension to the language provided by
the gcc compiler.
 
J

James Kuyper

Hello,

is it standard C... that the value obtained when evaluating a block is
the last expression in the block??

Example:
int b = ( {
int a;
a = 5;
a;
}
);

No. Blocks do not yield a value, and it's always a syntax error to use a
block in a context where a value would be needed. What you're describing
is an extension.
 
G

gwowen

Hello,

is it standard C... that the value obtained when evaluating a block is
the last expression in the block??

Example:
  int b = (   {
                  int a;
                  a = 5;
                  a;
                 }
             );

Thanks.

As Jacob and James have said, its a GCC extension. If you need more
information, they're called "statement expressions" or "compound
statement expressions" in the GCC manual, section 6.1.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top