D - struct default initializers
- Carlos Santander B. (28/28) Aug 18 2003 This code:
- Walter (1/1) Aug 18 2003 They should be. It's a bug. -Walter
- Sean L. Palmer (5/6) Aug 19 2003 Thank you! I thought it was because it would cause hidden code to be
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
Aug 18 2003
Thank you! I thought it was because it would cause hidden code to be generated. ;) Sean "Walter" <walter digitalmars.com> wrote in message news:bhro30$2663$1 digitaldaemon.com...They should be. It's a bug. -Walter
Aug 19 2003