Difference between revisions of "Types"

From MSX Game Library

Line 5: Line 5:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! Type !! Desc. !! [[SDCC]] equivalent
+
! Type !! Desc. !! [[SDCC]] equivalent !! Min !! Max
 
|-
 
|-
| '''<tt>bool</tt>''' || Boolean (8 bits) || <tt>unsigned char</tt>
+
| '''<tt>bool</tt>''' || Boolean (8 bits) || <tt>unsigned char</tt> || 0 || [[Boolean|not 0]]
 
|-
 
|-
| '''<tt>i8</tt>''' || 8 bits signed integer || <tt>signed char</tt>
+
| '''<tt>i8</tt>''' || 8 bits signed integer || <tt>signed char</tt> || -128 || 127
 
|-
 
|-
| '''<tt>u8</tt>''' || 8 bits unsigned integer || <tt>unsigned char</tt>
+
| '''<tt>u8</tt>''' || 8 bits unsigned integer || <tt>unsigned char</tt> || 0 || 255 (0xFF)
 
|-
 
|-
| '''<tt>i16</tt>''' || 16 bits signed integer || <tt>signed short</tt>
+
| '''<tt>i16</tt>''' || 16 bits signed integer || <tt>signed short</tt> || -32768 || 32767
 
|-
 
|-
| '''<tt>u16</tt>''' || 16 bits unsigned integer || <tt>unsigned short</tt>
+
| '''<tt>u16</tt>''' || 16 bits unsigned integer || <tt>unsigned short</tt> || 0 || 65535 (0xFFFF)
 
|-
 
|-
| '''<tt>i32</tt>''' || 32 bits signed integer || <tt>signed long</tt>
+
| '''<tt>i32</tt>''' || 32 bits signed integer || <tt>signed long</tt> || -2147483648 || 2147483647
 
|-
 
|-
| '''<tt>u32</tt>''' || 32 bits unsigned integer || <tt>unsigned long</tt>
+
| '''<tt>u32</tt>''' || 32 bits unsigned integer || <tt>unsigned long</tt> || 0 || 4294967295 (0xFFFFFFFF)
 
|-
 
|-
| '''<tt>i64</tt>''' || 64 bits signed integer || <tt>signed long long</tt>
+
| '''<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>
+
| '''<tt>u64</tt>''' || 64 bits unsigned integer || <tt>unsigned long long</tt> || 0 || 18,446,744,073,709,551,615 (0xFFFFFFFFFFFFFFFF)
 
|-
 
|-
| '''<tt>f32</tt>''' || 32 bits float (IEEE 754) || <tt>float</tt>
+
| '''<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>
+
| '''<tt>c8</tt>''' || 8 bits character (ASCII, UTF-8) || <tt>unsigned char</tt> || 0 || 255 (0xFF)
 
|-
 
|-
| '''<tt>c16</tt>''' || 16 bits character (UTF-16, JIS, etc.) || <tt>unsigned short</tt>
+
| '''<tt>c16</tt>''' || 16 bits character (UTF-16, JIS, etc.) || <tt>unsigned short</tt> || 0 || 65535 (0xFFFF)
 
|-
 
|-
| '''<tt>ptr</tt>''' || Pointer || <tt>void*</tt>
+
| '''<tt>ptr</tt>''' || Pointer || <tt>void*</tt> || 0x0000 || 0xFFFF
 
|-
 
|-
| '''<tt>callback</tt>''' || Callback default signature || <tt>void (*)(void)</tt>
+
| '''<tt>callback</tt>''' || Callback default signature || <tt>void (*)(void)</tt> || ||
 
|}
 
|}
  

Revision as of 16:04, 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 (0xFF)
i16 16 bits signed integer signed short -32768 32767
u16 16 bits unsigned integer unsigned short 0 65535 (0xFFFF)
i32 32 bits signed integer signed long -2147483648 2147483647
u32 32 bits unsigned integer unsigned long 0 4294967295 (0xFFFFFFFF)
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 (0xFFFFFFFFFFFFFFFF)
f32 32 bits float (IEEE 754) float 1,175494351e-38 3,402823466e+38
c8 8 bits character (ASCII, UTF-8) unsigned char 0 255 (0xFF)
c16 16 bits character (UTF-16, JIS, etc.) unsigned short 0 65535 (0xFFFF)
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: