Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Hallvard B Furuseth <h.b.furuseth@usit.uio.no> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | "struct hack" with non-character array[1] |
| Date | 2011-08-19 12:28 +0200 |
| Organization | University of Oslo, Norway |
| Message-ID | <hbf.20110819eide@bombur.uio.no> (permalink) |
I seem to remember the "struct hack" is safer if the fake
dynamic array has character type. If that's right, where/why?
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]; };
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.
The C FAQ does not mention it. And I know about C99
flexible array members, but that's not the question.
--
Hallvard
Back to comp.lang.c | Previous | Next — 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