Just a sample of the Echomail archive
COMPLANC:
[ << oldest | < older | list | newer > | newest >> ]
|  Message 242,443 of 243,097  |
|  Tim Rentsch to Kaz Kylheku  |
|  Re: Nice way of allocating flexible stru  |
|  14 Dec 25 22:48:42  |
 
From: tr.17687@z991.linuxsc.com
Kaz Kylheku <643-408-1753@kylheku.com> writes:
> Jonas Lund of https://whizzter.woorlic.org/ mentioned this
> trick in a HackerNews comment:
>
> Given:
>
> struct S {
> // ...
> T A[];
> };
>
> Don't do this:
>
> malloc(offsetof(S, A) + n * sizeof (T));
>
> But rather this:
>
> malloc(offsetof(S, A[n]));
>
> It's easy to forget that the second argument of offsetof is a
> designator, not simply a member name.
Clever but inadvisable. Even if the offsetof() expression compiles,
in most cases it either gives a value that is too small or is
undefined behavior.
--- SoupGate-Win32 v1.05
* Origin: you cannot sedate... all the things you hate (1:229/2)
|
[ << oldest | < older | list | newer > | newest >> ]
(c) 1994, bbs@darkrealms.ca