Difference between revisions of "Types"

From MSX Game Library

Line 11: Line 11:
 
| '''<tt>i8</tt>''' || 8 bits signed integer || <tt>signed char</tt> || -128 || 127
 
| '''<tt>i8</tt>''' || 8 bits signed integer || <tt>signed char</tt> || -128 || 127
 
|-
 
|-
| '''<tt>u8</tt>''' || 8 bits unsigned integer || <tt>unsigned char</tt> || 0 || 255 (0xFF)
+
| '''<tt>u8</tt>''' || 8 bits unsigned integer || <tt>unsigned char</tt> || 0 || 255
 
|-
 
|-
 
| '''<tt>i16</tt>''' || 16 bits signed integer || <tt>signed short</tt> || -32768 || 32767
 
| '''<tt>i16</tt>''' || 16 bits signed integer || <tt>signed short</tt> || -32768 || 32767
 
|-
 
|-
| '''<tt>u16</tt>''' || 16 bits unsigned integer || <tt>unsigned short</tt> || 0 || 65535 (0xFFFF)
+
| '''<tt>u16</tt>''' || 16 bits unsigned integer || <tt>unsigned short</tt> || 0 || 65535
 
|-
 
|-
| '''<tt>i32</tt>''' || 32 bits signed integer || <tt>signed long</tt> || -2147483648 || 2147483647
+
| '''<tt>i32</tt>''' || 32 bits signed integer || <tt>signed long</tt> || -2,147,483,648 || 2,147,483,647
 
|-
 
|-
| '''<tt>u32</tt>''' || 32 bits unsigned integer || <tt>unsigned long</tt> || 0 || 4294967295 (0xFFFFFFFF)
+
| '''<tt>u32</tt>''' || 32 bits unsigned integer || <tt>unsigned long</tt> || 0 || 4,294,967,295
 
|-
 
|-
 
| '''<tt>i64</tt>''' || 64 bits signed integer || <tt>signed long long</tt> || -9,223,372,036,854,775,808 || 9,223,372,036,854,775,807
 
| '''<tt>i64</tt>''' || 64 bits signed integer || <tt>signed long long</tt> || -9,223,372,036,854,775,808 || 9,223,372,036,854,775,807
 
|-
 
|-
| '''<tt>u64</tt>''' || 64 bits unsigned integer || <tt>unsigned long long</tt> || 0 || 18,446,744,073,709,551,615 (0xFFFFFFFFFFFFFFFF)
+
| '''<tt>u64</tt>''' || 64 bits unsigned integer || <tt>unsigned long long</tt> || 0 || 18,446,744,073,709,551,615
 
|-
 
|-
 
| '''<tt>f32</tt>''' || 32 bits float (IEEE 754) || <tt>float</tt> || 1,175494351e-38 || 3,402823466e+38
 
| '''<tt>f32</tt>''' || 32 bits float (IEEE 754) || <tt>float</tt> || 1,175494351e-38 || 3,402823466e+38
 
|-
 
|-
| '''<tt>c8</tt>''' || 8 bits character (ASCII, UTF-8) || <tt>unsigned char</tt> || 0 || 255 (0xFF)
+
| '''<tt>c8</tt>''' || 8 bits character (ASCII, UTF-8) || <tt>unsigned char</tt> || 0 || 255
 
|-
 
|-
| '''<tt>c16</tt>''' || 16 bits character (UTF-16, JIS, etc.) || <tt>unsigned short</tt> || 0 || 65535 (0xFFFF)
+
| '''<tt>c16</tt>''' || 16 bits character (UTF-16, JIS, etc.) || <tt>unsigned short</tt> || 0 || 65535
 
|-
 
|-
 
| '''<tt>ptr</tt>''' || Pointer || <tt>void*</tt> || 0x0000 || 0xFFFF
 
| '''<tt>ptr</tt>''' || Pointer || <tt>void*</tt> || 0x0000 || 0xFFFF

Revision as of 16:05, 24 March 2024

You can use standard C types to define variables but MSXgl provide some shortcut that help to write short code and makes data size and sign explicit (which is so important for creating efficient code on a Z80).

MSXgl's types can be found in core.h.

Type Desc. SDCC equivalent Min Max
bool Boolean (8 bits) unsigned char 0 not 0
i8 8 bits signed integer signed char -128 127
u8 8 bits unsigned integer unsigned char 0 255
i16 16 bits signed integer signed short -32768 32767
u16 16 bits unsigned integer unsigned short 0 65535
i32 32 bits signed integer signed long -2,147,483,648 2,147,483,647
u32 32 bits unsigned integer unsigned long 0 4,294,967,295
i64 64 bits signed integer signed long long -9,223,372,036,854,775,808 9,223,372,036,854,775,807
u64 64 bits unsigned integer unsigned long long 0 18,446,744,073,709,551,615
f32 32 bits float (IEEE 754) float 1,175494351e-38 3,402823466e+38
c8 8 bits character (ASCII, UTF-8) unsigned char 0 255
c16 16 bits character (UTF-16, JIS, etc.) unsigned short 0 65535
ptr Pointer void* 0x0000 0xFFFF
callback Callback default signature void (*)(void)

Related constants:

#define NULL	0	// Pointer "NULL" value
#define TRUE	1	// Value for "TRUE" boolean
#define FALSE	0	// Value for "FALSE" boolean

See also: