Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: "struct hack" with non-character array[1] |
| Date | 2011-08-19 23:15 +1200 |
| Message-ID | <9b6uv8Fr4mU1@mid.individual.net> (permalink) |
| References | <hbf.20110819eide@bombur.uio.no> |
On 08/19/11 10:28 PM, Hallvard B Furuseth wrote:
> I seem to remember the "struct hack" is safer if the fake
> dynamic array has character type. If that's right, where/why?
Why should it be?
> Maybe in C99, since the struct hack is undefined in C89? Or
> real life implementations, nothing to do with the standard?
>
> That is,
> typedef<char or int> T;
> struct hack { Foo foo; T dynamic[1]; };
make that
struct hack { Foo foo; T dynamic[]; };
for C99.
> struct hack h = malloc(sizeof *h) + sizeof(T)*n;
> .... use h->dynamic[0..n-1] ...;
> would be safer with T = char than with T = int.
It wouldn't compile with either. The flexible array member is irrelevant.
--
Ian Collins
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
"struct hack" with non-character array[1] Hallvard B Furuseth <h.b.furuseth@usit.uio.no> - 2011-08-19 12:28 +0200
Re: "struct hack" with non-character array[1] Ian Collins <ian-news@hotmail.com> - 2011-08-19 23:15 +1200
Re: "struct hack" with non-character array[1] Hallvard B Furuseth <h.b.furuseth@usit.uio.no> - 2011-08-19 15:12 +0200
Re: "struct hack" with non-character array[1] falk@rahul.net (Edward A. Falk) - 2011-08-19 16:41 +0000
Re: "struct hack" with non-character array[1] Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-19 08:01 -0400
Re: "struct hack" with non-character array[1] James Kuyper <jameskuyper@verizon.net> - 2011-08-19 08:40 -0400
Re: "struct hack" with non-character array[1] Keith Thompson <kst-u@mib.org> - 2011-08-19 09:41 -0700
csiph-web