Eric Sosman said:
Clint said:
What about the following is not computable? It seems that the size of foo
is easily computable:
typedef struct {
char *name;
char *data;
} Foo;
int main(void)
{
char data[] = { 'a', 'b', 'c', 'd' };
Foo foo = { "bar", data };
return 0;
}
The size of `foo' is known, yes. What's not known is
the address of the automatic ("stack-resident," on many
implementations) variable `data'.
In C89 this is certainly true, but in C99 it _seems_ to be allowed,
but unfortunately I'm unable to find a corresponding section in the
standard. Maybe someone can help out with a quote? Thanks.
Regards
C90 said this in the constraints section of 6.5.7, "Initialization":
========
All the expressions in an initializer for an object that has static
storage duration or in an initializer list for an object that has
aggregate or union type shall be constant expressions
========
C99 says this in the constraints section of 6.7.8, "Initialization":
========
All the expressions in an initializer for an object that has static
storage duration shall be constant expressions or string literals.
========
So initializing an aggregate (array or structure) or union type with a
non-constant expression is no longer a constraint violation provided
the aggregate does not have static storage duration.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq