sizeof(type) in various systems

D

dam_fool_2003

1)As i was going through the previous threads of clc I come accross that
sizeof(type) could varies according to the system.
limit.h macro constant(CHAR_xxx,INT_xxx,etc) will do the job of allocatating
the number of bits according to the system. I am wrong in understanding?

2)can any body post the details of sizeof(type) in different systems


NOTE:If this is a OT then direct me or if this Question asked in previous
thread can any body give the link.

Thanks

----------------
DON'T MAIL ME
----------------
 
E

Emmanuel Delahaye

In said:
1)As i was going through the previous threads of clc I come accross that
sizeof(type) could varies according to the system.

If you meant "the value returned by the expression 'sizeof (type)'", you are
correct. To be more generic, say that it can vary according to the
implementation. (such compiler running on such system running on such
machine)

For example, on my PC, I have Windows 98 SE. If I use Borland C 3.1 sizeof
(int) is 2. If I use VC++6 or Dev-C++, it's 4.
limit.h macro constant(CHAR_xxx,INT_xxx,etc) will do the job of
allocatating the number of bits according to the system. I am wrong in
understanding?

Actually, the values on limits.h are informative. They inform the programmer
about the limits supported by the types on this peculiar implementation of
the C-language. If I follow my previous examples, here are the values I have
in the <limits.h> headers of Borland C++ 3.1 :

#define INT_MAX 0x7FFF
#define INT_MIN ((int)0x8000)
#define UINT_MAX 0xFFFFU

and of Dev-C++ :

#define INT_MAX 2147483647
#define INT_MIN (-INT_MAX-1)

#define UINT_MAX 0xffffffff

*These values must not be changed by the user*. They belong to the
implementation said:
2)can anybody post the details of sizeof(type) in different systems

Why do you want that exactly ? How such an information could be
exhaustive or useful ?
 
R

Richard Bos

1)As i was going through the previous threads of clc I come accross that
sizeof(type) could varies according to the system.
limit.h macro constant(CHAR_xxx,INT_xxx,etc) will do the job of allocatating
the number of bits according to the system. I am wrong in understanding?

You are wrong. First of all, it's called <limits.h>, note spelling.
Then, the macros in <limits.h> do not allocate anything whatsoever; they
are, as you say, simple constants. They evaluate to numbers, not to
function calls. Finally, the numbers they evaluate to are, surprise,
usually _limits_, not bit counts; that is, if you have an unsigned int
with 16 value bits, then UINT_MAX will be 2**16 == 65536, _not_ 16.

The one exception to this is CHAR_BIT, which gives you the number of
bits in a char. Together with sizeof, this one macro can be used to
figure out the bit count used by a type or an object - but note, this
bit count includes not just value and sign bits, but also padding bits.
Thus, it may (usually isn't for integers, but _is_ allowed to) be larger
than seems consistent with the values in said:
2)can any body post the details of sizeof(type) in different systems

Not me, but why do you need to know how large a short int is under
Zibble C on an Arawak machine?

Richard
 
K

Keith Thompson

Finally, the numbers they evaluate to are, surprise, usually
_limits_, not bit counts; that is, if you have an unsigned int with
16 value bits, then UINT_MAX will be 2**16 == 65536, _not_ 16.

<QUIBBLE>2**16-1 == 65535</QUIBBLE>
 
R

Richard Bos

Keith Thompson said:
<QUIBBLE>2**16-1 == 65535</QUIBBLE>

Bloody 'ell. I even had n869 in front of me when I typed that. Either I
can't read, I can't write, or I can't do math, you choose.

Richard
 
D

Dan Pop

In said:
2)can any body post the details of sizeof(type) in different systems

Yup. All you want to know is that sizeof(char) is 1 on different systems,
so you never need to write sizeof(char) in your portable C code. For
anything else, use sizeof, because this is why it exists in the language.

Dan
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top