sizeof(data type)

A place to discuss the science of computers and programs, from algorithms to computability.

Formal proofs preferred.

Moderators: phlip, Moderators General, Prelates

mathmari
Posts: 81
Joined: Sat Apr 27, 2013 11:58 pm UTC

sizeof(data type)

Postby mathmari » Mon Jun 10, 2013 12:25 pm UTC

Hi everyone!!! :D
I have a question...
At some compilers,if we work on a a 32-bit operating system, (sizeof)int=2...
A this case:
(sizeof)double=?
(sizeof)float=?
(sizeof)char=?
Thnaks!

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: sizeof(data type)

Postby EvanED » Mon Jun 10, 2013 2:19 pm UTC

sizeof(char) will always be 1 or your compiler is broken; that's mandated by the standard. The others can still be whatever, though float is still likely to be 4 and double 8.

mathmari
Posts: 81
Joined: Sat Apr 27, 2013 11:58 pm UTC

Re: sizeof(data type)

Postby mathmari » Mon Jun 10, 2013 10:16 pm UTC

Ok!!! Thanks!!!

DeGuerre
Posts: 51
Joined: Mon Feb 04, 2008 6:41 am UTC

Re: sizeof(data type)

Postby DeGuerre » Wed Jun 12, 2013 2:01 am UTC

EvanED wrote:sizeof(char) will always be 1 or your compiler is broken; that's mandated by the standard.

That's correct, but the catch is that CHAR_BITS need not be 8 according to the standard (though it must be at least 8). If you need guarantees on the size of an integer, use stdint.h.
EvanED wrote:The others can still be whatever, though float is still likely to be 4 and double 8.

The C standard doesn't specify minimum values for these, but there are effective minimum sizes because of the minimum values of the constants in float.h.

mathmari
Posts: 81
Joined: Sat Apr 27, 2013 11:58 pm UTC

Re: sizeof(data type)

Postby mathmari » Fri Jun 14, 2013 10:50 pm UTC

Nice..Thank you!!!


Return to “Computer Science”

Who is online

Users browsing this forum: No registered users and 7 guests