Skip to main content

IAR Embedded Workbench for RISC-V 3.40

Basic data types—integer types

In this section:

The compiler supports both all Standard C basic data types and some additional types.

Integer types—an overview

This table gives the size and range of each integer data type:

Data type

Size

Range

Alignment

bool

8 bits

0 to 1

1

char

8 bits

0 to 255

1

signed char

8 bits

-128 to 127

1

unsigned char

8 bits

0 to 255

1

signed short

16 bits

-32768 to 32767

2

unsigned short

16 bits

0 to 65535

2

signed int

32 bits

-231 to 231-1

4

unsigned int

32 bits

0 to 232-1

4

signed long (RV32)

signed long (RV64)

32 bits

64 bits

-231 to 231-1

-263 to 263-1

4

8

unsigned long (RV32)

unsigned long (RV64)

32 bits

64 bits

0 to 232-1

0 to 264-1

4

8

signed long long

64 bits

-263 to 263-1

8

unsigned long long

64 bits

0 to 264-1

8

Table 77. Integer types 


Signed variables are represented using the two’s complement form.

Bool

The bool data type is supported by default in the C++ language. If you have enabled language extensions, the bool type can also be used in C source code if you include the file stdbool.h. This will also enable the boolean values false and true.

The long long type

The long long data type is supported with restrictions:

long long variables must be stored with 8-byte alignment.

The enum type

The compiler will try to use the type int to hold enum constants, preferring signed rather than unsigned. To force the compiler to use the smallest type, use the option ‑‑short_enums, see ‑‑short_enums.

When IAR language extensions are enabled, and in C++, the enum constants and types can also be of the type unsigned int, long long, or unsigned long long.

To make the compiler use a larger type than it would automatically use, define an enum constant with a large enough value. For example:

/* Define enum as an unsigned long long */
enum Cards{Spade1, Spade2,
           DontUseInt=0x0FFFF'FFFF'FFFF'FFFF};

See also the C++ enum struct syntax.

The char type

The char type is by default unsigned in the compiler, but the ‑‑char_is_signed compiler option allows you to make it signed.

Note

The library is compiled with the char type as unsigned.

The wchar_t type

The wchar_t data type is 4 bytes and the encoding used for it is UTF-32.

The char16_t type

The char16_t data type is 2 bytes and the encoding used for it is UTF-16.

The char32_t type

The char32_t data type is 4 bytes and the encoding used for it is UTF-32.