Re: #define....



remco wrote:
> "Robby" <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:9A5116B7-46B0-4D5D-AC9C-6BB55DBA1360@xxxxxxxxxxxxxxxx
>>
>> #define dim(x) (sizeof(x) / sizeof(x[0]))
>>
>> I am trying to understand what this line has to do with the rest of the
>> code.
[...]
> For instance, if you want to get the number of items you would use that
> snippit.
> You'll find it all over ancient C/C++ code perhaps in a more familar form:
>
> DWORD mydwords[[100];
>
> DWORD numberOfBytes = sizeof(mydwords); // will be 100 * however long a
> DWORD is (4)
> DWORD numberOfItems = sizeof(mydwords)/sizeof(mydwords[0]); // number will
> be 100

Just for your info, the brackets are not necessary as sizeof is not a
function and you sometimes see the * operator instead of []:

size_t const count = (sizeof array)/(sizeof *array);

Uli

.



Relevant Pages


Quantcast