Variable structure size -- ANSI ?
Stephen R. van den Berg
berg at marvin.e17.physik.tu-muenchen.de
Thu Apr 11 20:48:27 AEST 1991
Michael N Johnston writes:
]>struct foo {
]>unsigned short recsize;
]>unsigned short num;
]>char info [24];
]>byte flags;
]>char filename[1]
]>};
]>Where, foo.filename is a placeholder for a variable length string.
]If you plan to store a char array in filename DON'T. Use char *filename
]and point this to your actual array. Using your origional declaration
]and doing something like strcpy(foo_ptr->filename, "abcde") will lead
]to disaster.
Why should this lead to disaster? Is this not allowed by ANSI?
If you can make sure that you have malloced more than enough space for the
structure, shouldn't you be able to use all this space by doing just that?
--
Sincerely, berg at marvin.e17.physik.tu-muenchen.de
Stephen R. van den Berg.
"I code it in 5 min, optimize it in 90 min, because it's so well optimized:
it runs in only 5 min. Actually, most of the time I optimize programs."
More information about the Comp.lang.c
mailing list