CTRE Phoenix C++ 5.33.1
Platform-pack.h
Go to the documentation of this file.
1/* Copyright (C) Cross The Road Electronics 2024 */
2/**
3 * This header implements macros for creating storage objects
4 * with 1 byte (8bit) packing across all supported platforms.
5 *
6 * Example use...
7 *
8 * PACK_PREFIX
9 * typedef struct _nameOfType_t
10 * {
11 * uint8_t aByte;
12 * uint16_t aShort;
13 * uint32_t aWord;
14 * } PACK_ATTRIB nameOfType_t;
15 * PACK_SUFFIX
16 *
17 */
18#pragma once
19
20#ifdef __GNUC__
21 /* All GCC versions supports packed attribute */
22 #define PACK_PREFIX /* empty */
23 #define PACK_SUFFIX /* empty */
24 #define PACK_ATTRIB __attribute__ ((packed))
25#else
26 /* MSVC uses pragma's to being and end regions of code */
27 #define PACK_PREFIX __pragma(pack(push, 1))
28 #define PACK_SUFFIX __pragma(pack(pop))
29 #define PACK_ATTRIB /* empty */
30#endif
31
32/**
33 * CTRE_ASSERT(cond)
34 * This can be moved into a seperate header later (Platform-assert).
35 */
36#if defined(__GNUC__)
37 #define CTRE_ASSERT(cond) do{}while(0)
38#elif defined(WIN32) || defined(_WIN32) || defined(_WIN64)
39 /* Windows OS */
40 #if defined (_DEBUG)
41 /* Windows OS - Debug build */
42 #include <assert.h>
43 #define CTRE_ASSERT(cond) assert(cond)
44 #else
45 /* Windows OS - Release build */
46 #define CTRE_ASSERT(cond) do{}while(0)
47 #endif
48#else
49 #define CTRE_ASSERT(cond) do{}while(0)
50#endif
51
52/**
53* CTRE_Application_CrashHandler(cond)
54* This can be moved into a seperate header later.
55*/
56#if defined(WIN32) || defined(_WIN32) || defined(_WIN64)
57 #define CTRE_IMPLEMENT_SHUTDOWN_HANDLER(shutdown_handler) \
58 static void shutdown_handler(); \
59 BOOL WINAPI CTRE_Global_ConsoleHandlerRoutine(DWORD dwCtrlType) { \
60 if (dwCtrlType == CTRL_CLOSE_EVENT) { shutdown_handler(); } \
61 return FALSE; \
62 } \
63 static void shutdown_handler()
64
65
66 #define CTRE_REGISTER_SHUTDOWN_HANDLER(shutdown_handler) \
67 do{ (void)SetConsoleCtrlHandler(CTRE_Global_ConsoleHandlerRoutine, TRUE); } while(0)
68
69#else
70
71 #define CTRE_IMPLEMENT_SHUTDOWN_HANDLER(shutdown_handler) static void shutdown_handler(int signo)
72 #define CTRE_REGISTER_SHUTDOWN_HANDLER(shutdown_handler)
73
74#endif