diff --git a/src/VM/VM.h b/src/VM/VM.h index a141f27..5b54297 100644 --- a/src/VM/VM.h +++ b/src/VM/VM.h @@ -45,7 +45,7 @@ typedef struct VM { }; VMState state; - char* error_message; + NULLABLE(char* error_message); u8* data; size_t data_size; diff --git a/src/instructions/impl/SYS.c b/src/instructions/impl/SYS.c index 1a9e651..825b81e 100644 --- a/src/instructions/impl/SYS.c +++ b/src/instructions/impl/SYS.c @@ -1,6 +1,6 @@ #include "impl_macros.h" -FILE* fileFromN(VM* vm, size_t pos, u32 file_n){ +NULLABLE(FILE* fileFromN(VM* vm, size_t pos, u32 file_n)){ FILE* f = NULL; switch(file_n){ case 0: f = stdin; break; diff --git a/src/instructions/instructions.c b/src/instructions/instructions.c index bb4f01b..871f09a 100644 --- a/src/instructions/instructions.c +++ b/src/instructions/instructions.c @@ -16,7 +16,7 @@ const Instruction instructions[] = { }; const size_t instructions_count = sizeof(instructions)/sizeof(instructions[0]); -const Instruction* Instruction_getFromOpcode(u8 opcode){ +NULLABLE(const Instruction* Instruction_getFromOpcode(u8 opcode)){ if(opcode >= instructions_count) return NULL; diff --git a/src/instructions/instructions.h b/src/instructions/instructions.h index a720861..332ae40 100644 --- a/src/instructions/instructions.h +++ b/src/instructions/instructions.h @@ -18,7 +18,7 @@ typedef struct Instruction { /// @brief get instruction info from table /// @param opcode any byte /// @return ptr to struct or NULL -const Instruction* Instruction_getFromOpcode(u8 opcode); +NULLABLE(const Instruction* Instruction_getFromOpcode(u8 opcode)); i32 NOP_impl(VM* vm, size_t pos); i32 PUSH_impl(VM* vm, size_t pos); diff --git a/src/main.c b/src/main.c index e657940..b83f590 100644 --- a/src/main.c +++ b/src/main.c @@ -4,7 +4,7 @@ #define arg_is(STR) (strcmp(argv[argi], STR) == 0) i32 main(const i32 argc, const char** argv){ - const char* filename = NULL; + const char* NULLABLE(filename) = NULL; for(i32 argi = 1; argi < argc; argi++){ if(arg_is("-h") || arg_is("--help")){ diff --git a/src/std.h b/src/std.h index d3321cc..2ac9d64 100644 --- a/src/std.h +++ b/src/std.h @@ -24,4 +24,7 @@ typedef u8 bool; #define true 1 #define false 0 -#define printfe(FORMAT, ...) fprintf(stderr, FORMAT ,##__VA_ARGS__) \ No newline at end of file +#define printfe(FORMAT, ...) fprintf(stderr, FORMAT ,##__VA_ARGS__) + +/// @warning pointer can be null +#define NULLABLE(DECLARATION) DECLARATION