| |
| Posted by Carlos Santander B. | PermalinkReply |
|
Carlos Santander B.
| This code:
void main() {
struct A { char c='c'; int i=5; float f=3.14; }
enum B { X, Y, Z }
static A [B] a;
a[B.X].c='x';
a[B.Y].i=-1;
a[B.Z].f=1000;
printf("X: c=%c, i=%d, f=%f\nY: c=%c, i=%d, f=%f\nZ: c=%c, i=%d, f=%f\n",
a[B.X].c,a[B.X].i,a[B.X].f,a[B.Y].c,a[B.Y].i,a[B.Y].f,a[B.Z].c,a[B.Z].i,a[B.
Z].f);
}
Produces this output:
X: c=x, i=0, f=0.000000
Y: c= , i=-1, f=0.000000
Z: c= , i=0, f=1000.000000
Notice A is declared static, so I thought the default initializers would be used.
However, previously I was under the impression default struct initializers could be also used for non-static variables (then I read the docs and I discovered they were only for static variables). This leads me to this question: why can't they (initializers) be used for non-static variables?
-------------------------
Carlos Santander
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.510 / Virus Database: 307 - Release Date: 2003-08-14
|