Interview Questions

Since C doesnt define sizes exactly

C Interview Questions and Answers


(Continued from previous question...)

Since C doesnt define sizes exactly

Since C doesn't define sizes exactly, I've been using typedefs like int16 and int32. I can then define these typedefs to be int, short, long, etc. depending on what machine I'm using. That should solve everything, right?

If you truly need control over exact type sizes, this is the right approach. There remain several things to be aware of:

* There might not be an exact match on some machines. (There are, for example, 36-bit machines.)
* A typedef like int16 or int32 accomplishes nothing if its intended meaning is ``at least'' the specified size, because types int and long are already essentially defined as being ``at least 16 bits'' and ``at least 32 bits,'' respectively.
* Typedefs will never do anything about byte order problems (e.g. if you're trying to interchange data or conform to externally-imposed storage layouts).
* You no longer have to define your own typedefs, because the Standard header contains a complete set.

(Continued on next question...)

Other Interview Questions