Difference between revisions of "Types"
From MSX Game Library
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | You can use standard C types 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). | + | 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 [https://github.com/aoineko-fr/MSXgl/blob/main/engine/src/core.h core.h]. | MSXgl's types can be found in [https://github.com/aoineko-fr/MSXgl/blob/main/engine/src/core.h core.h]. | ||
Line 5: | Line 5: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
− | ! Type !! Desc. !! SDCC equivalent | + | ! Type !! Desc. !! [[SDCC]] equivalent !! Min value !! Max value |
|- | |- | ||
− | | '''<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 |
|- | |- | ||
− | | '''<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 |
|- | |- | ||
− | | '''<tt>i32</tt>''' || 32 bits signed integer || <tt>signed long</tt> | + | | '''<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> | + | | '''<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> | + | | '''<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 |
|- | |- | ||
− | | '''<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 |
|- | |- | ||
− | | '''<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 |
|- | |- | ||
− | | '''<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> || || |
|} | |} | ||
− | Related | + | Related constants: |
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
#define NULL 0 // Pointer "NULL" value | #define NULL 0 // Pointer "NULL" value |
Latest revision as of 17:40, 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 value | Max value |
---|---|---|---|---|
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:
- Page about usage of boolean in MSXgl.
- SDCC documentation