This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

About Representation of C data types



 

Hi,all,

I saw a table C table types showed in following .

What did items in the representation mean, and the different between them.In my opinin,variables are binary stored in memory.

TYPE

Size

Representation

Minimum

Maximum

char,signed char

8

ASCII

-128

127

unsigned char,bool

8

ASCII

0

255

short, signed short

16

2's complement

-32768

32767

unsigned short

16

Binary

0

65535

int, signed int

16

2's complement

-32768

32767

unsigned int

16

Binary

0

65535

long, signed long

32

2's complement

-2147483648

2147483647

unsigned long

32

Binary

0

4294967295

long long,signed long long

64

2's complement

-9223372236854775808

9223372236854775807

unsigned long long

64

Binary

0

184467440737095551615

enum

16

2's complement

-32768

32767

float

32

IEEE 32-bit

1.175495E-38

3.402823E+38

double

32

IEEE 33-bit

1.175495E-38

3.402823E+38

long double

32

IEEE 34-bit

1.175495E-38

3.402823E+38

pointers,references, pointer to data members

16

Binary

0

0xFFFF

MSP430x large-data model pointers,references,pointer to data members

20

Binary

0

0xFFFFF

MSP430 function pointers

16

Binary

0

0xFFFF

MSP430X function pointers

20

Binary

0

0xFFFFF

 

  • Garvin Tan said:
    I saw a table C table types

    Where did you see it?

    Garvin Tan said:
    What did items in the representation mean

    Didn't the context of the table explain that?

    Whithout knowing the context, it's impossible to know exactly what it was intended to mean or convey!

    At a guess, it looks to me like a table of how a debugger will display various data types;  presumably, these are defaults - and can be changed if required.

    Garvin Tan said:
    the different between them

    Again, didn't the context of the table explain that?

    Any basic textbook - or a bit of googling - should explain what "ASCII", "2's complement", "Binary", and "IEEE" formats mean...

    Garvin Tan said:
    In my opinin

    It's not your opinion that counts - it's whatever is defined by the particular tool or device. You must study its documentation for details...

    Garvin Tan said:
    variables are binary stored in memory

    Although it is true that the memory hardware just stores 1s and 0s[1] (ie, binary), those 1s and 0s can be used in many different ways to represent many different types of data; eg,

    • To represent printable characters - commonly using ASCII encoding;
       
    • To represent unsigned integral numeric values (values never less than zero);
       
    • To represent signed integral numeric values (values above, below, or equal to zero);
       
    • To represent non-integral values (with a fractional part);
       
    • To represent a memory address;
       
    • As raw, binary bit patterns;
       
    • etc, etc,...


    [1] Note: the memory hardware itself doesn't even know about "1" or "0" - it just knows about voltage levels. The use of "1" and "0" is just a convenient representation...

  • What does it mean IEEE 33-bit (for double) and IEEE 34-bit (for long double) ?
    I guess that it is typo. I expect IEEE 32-bit in both cases.
  • Petr Kras said:
    What does it mean IEEE 33-bit (for double) and IEEE 34-bit (for long double) ?
    I guess that it is typo. I expect IEEE 32-bit in both cases.

    Agreed. What I think has happened is that the table was entered using a spreadsheet tool, and it decided to auto-increment the number of bits when copy/pasting.

  • >variables are binary stored in memory
    Yes they are.
    But as C will use correct assembler instruction for it or emulate FPU in software etc, it needs to know the type.
    Plus it also warns you from passing data with incompatible types to each other, but with type casting may be overridden.

  • The table is from SLAU132, section 5.5 (MSP430 Optimizing C/C++ Compiler v 4.1 User's Guide)

    There's the context.

**Attention** This is a public forum