[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sizeof



At  1:51 PM 1/10/94 -0500, Robert Bruce Findler wrote:
>Excerpts from internet.listserv.info-mcl: 10-Jan-94 Re: sizeof by Doug
>F. Technology@flavo
>> >Is there an equivalent of the C sizeof macro in MCL?
>> I don't think so; what would it do?
>
>It would return the size in bytes of a structure. Earlier I found myself
>making a CTabHandle, by doing something like this:
>
>(make-record :ColorTable :storage :Handle
>             :length (+ (sizeof :ColorTable)
>                        (* num-colors (sizeof :ColorSpec))))

As Mark Tapia said: sizeof in C is the same as record-length in MCL.

Your example is mis-parenthesized. It should be:

(make-record (:ColorTable :storage :Handle
                          :length (+ (record-length :ColorTable)
                                     (* num-colors
                                        (record-length :ColorSpec)))))

Actually, this allocates room for one more ColorSpec than is necessary,
since the ColorTable record includes one ColorSpec in its definition.
Minimal storage for num-colors ColorSpec's will come from:

(make-record (:ColorTable :storage :Handle
                          :length (+ (record-length :ColorTable)
                                     (* (1- num-colors)
                                        (record-length :ColorSpec)))))