----Original Message----
>From: [EMAIL PROTECTED]
>Sent: 19 September 2005 12:09

> "Dave Korn" writes:
> 
>> ----Original Message----
>>> From: Richard Henderson
>>> Sent: 19 September 2005 11:26

>>> In the case of the (fake) flexible array member, you do not know
>>> how large the object allocated from malloc was unless you can
>>> track down the actual malloc call.
>> 
>>   Do you suppose the idiom is common enough that VRP could special-case
>> "arrays of size 1 at the end of a struct" ?
> 
> it could be array of size 2, 3, 4, 5, ...

  I've seen this trick used again and again and again, and *I* haven't
_ever_ seen anyone use anything except an array size of [1] in this place.
That is to say, I've seen a lot of code that says (to start with your
example):

<-------------------------------------
     typedef struct {
        int data[1];
     } foo;

     foo* p = (foo *) malloc (sizeof (foo) + N * sizeof (int));
-------------------------------------
[dk note: I would expect to see (N-1) * sizeof (int) here more usually.
well, either that, or I would expect the comment to read 'enough room for
N+1 ints'.]
-------------------------------------
     // there are enough room for N ints, and the store is properly
     // aligned.

     for (int i = 0; i < N; ++i)
           p->data[i] = frobnicate (N, i);
------------------------------------->

but I have never, never, ever seen code that says:

<-------------------------------------
     typedef struct {
        int data[3];
     } foo;

     foo* p = (foo *) malloc (sizeof (foo) + (N-3) * sizeof (int));
     // there are enough room for N ints, and the store is properly
     // aligned.

     for (int i = 0; i < N; ++i)
           p->data[i] = frobnicate (N, i);
------------------------------------->

  Have you?


    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

Reply via email to