about array declare with parenthesis mark

A

anson

#include <stdio.h>

int
main(void)

{
int s[3] = { 1, (3,2), (6, 5, 4)};

printf ("%d %d %d", s[0], s[1], s[2]);

}
~
~
1 2 4

this means the last one within the parenthesis mark will works ,
what about others ?
what happened and why .
I want to know ...
it's a part of language or depend on implement ?
 
W

Walter Roberson

R

Richard Heathfield

anson said:
#include <stdio.h>

int
main(void)

{
int s[3] = { 1, (3,2), (6, 5, 4)};

printf ("%d %d %d", s[0], s[1], s[2]);

}
~
~
1 2 4

this means the last one within the parenthesis mark will works ,
what about others ?
what happened and why .
I want to know ...
it's a part of language or depend on implement ?


See page 62 of Kernighan and Ritchie's "The C Programming Language", 2nd
edition.
 
J

Jack Klein

#include <stdio.h>

int
main(void)

{
int s[3] = { 1, (3,2), (6, 5, 4)};

printf ("%d %d %d", s[0], s[1], s[2]);

}
~
~
1 2 4

this means the last one within the parenthesis mark will works ,
what about others ?
what happened and why .
I want to know ...
it's a part of language or depend on implement ?

Actually this code is not valid C under versions of the C standard
earlier than 1999. It is valid under C99 and later, but it would not
be if the array 's' was defined with static storage duration.

All objects with static storage duration under all versions of the C
standard, and all aggregate objects prior to C99, must be initialized
with constant expressions. And the comma operator is not allowed in
constant expressions.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 

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,800
Messages
2,569,657
Members
45,416
Latest member
MyraTrotte
Top