help me out

K

Keith Thompson

Eric Sosman said:
IMHO, the correct answer to the O.P.'s question


... is to use `sizeof(X)'. The question doesn't seek to
explore one's knowledge of C, but one's ability to spot
and reject a stupid specification.

I don't *entirely* agree. There are (clumsy) solutions involving
pointer arithmetic. Being able to determine the size of a type
without using sizeof does demonstrate a knowledge of how pointer
arithmetic works in C -- and there could be problems requiring similar
solutions for which the language doesn't provide a built-in operator.
Determining the alignment for a type is one example; offsetof would be
another if it weren't already declared in <stddef.h>.

But of course there is absolutely no reason to determine the size of a
type without using sizeof in the real world. That's what sizeof is
for, after all.

IMHO, a better response to the OP's question is:

*Why* can't you use sizeof?

I wouldn't be inclined to provide a solution until that question is
answered.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,184
Messages
2,570,973
Members
47,528
Latest member
AnaHawley8

Latest Threads

Top