Added macro to do safe subtractions on a word
Default C just lets overflows occur for subtraction, so this macro will default to 0 if the subtraction causes an overflow.
This commit is contained in:
@@ -49,9 +49,10 @@ typedef enum
|
|||||||
DATA_TYPE_WORD,
|
DATA_TYPE_WORD,
|
||||||
} data_type_t;
|
} data_type_t;
|
||||||
|
|
||||||
#define DBYTE(BYTE) ((data_t){.as_byte = (BYTE)})
|
#define DBYTE(BYTE) ((data_t){.as_byte = (BYTE)})
|
||||||
#define DHWORD(HWORD) ((data_t){.as_hword = (HWORD)})
|
#define DHWORD(HWORD) ((data_t){.as_hword = (HWORD)})
|
||||||
#define DWORD(WORD) ((data_t){.as_word = (WORD)})
|
#define DWORD(WORD) ((data_t){.as_word = (WORD)})
|
||||||
|
#define WORD_SAFE_SUB(W, SUB) ((W) > (SUB) ? ((W) - (SUB)) : 0)
|
||||||
|
|
||||||
#define HWORD_SIZE sizeof(hword)
|
#define HWORD_SIZE sizeof(hword)
|
||||||
#define WORD_SIZE sizeof(word)
|
#define WORD_SIZE sizeof(word)
|
||||||
|
|||||||
Reference in New Issue
Block a user