{"id":26917103,"url":"https://github.com/ignackocom/cmacroextensions","last_synced_at":"2025-04-01T19:51:23.781Z","repository":{"id":284885420,"uuid":"956352413","full_name":"ignackocom/CMacroExtensions","owner":"ignackocom","description":"C Macro Extensions, a collection of commonly used c macros","archived":false,"fork":false,"pushed_at":"2025-03-28T06:51:09.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T07:32:10.114Z","etag":null,"topics":["c","code","extension","extensions","macro","macros","mit-license","source"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ignackocom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-28T05:32:51.000Z","updated_at":"2025-03-28T06:55:03.000Z","dependencies_parsed_at":"2025-03-28T07:32:19.655Z","dependency_job_id":"ab906b9b-f208-4d77-b37a-243717a9d503","html_url":"https://github.com/ignackocom/CMacroExtensions","commit_stats":null,"previous_names":["ignackocom/cmacroextensions"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignackocom%2FCMacroExtensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignackocom%2FCMacroExtensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignackocom%2FCMacroExtensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignackocom%2FCMacroExtensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ignackocom","download_url":"https://codeload.github.com/ignackocom/CMacroExtensions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246706619,"owners_count":20820785,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","code","extension","extensions","macro","macros","mit-license","source"],"created_at":"2025-04-01T19:51:23.094Z","updated_at":"2025-04-01T19:51:23.773Z","avatar_url":"https://github.com/ignackocom.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CMacroExtensions\nC Macro Extensions, a library of commonly used macros in the C language.\n\nExample of use\n\n```\n#include \u003cstdio.h\u003e\n#include \u003cstdarg.h\u003e\n\n#if defined(__clang__)\n#pragma clang diagnostic ignored \"-Wc23-compat\"\n#endif /* defined(__clang__) */\n\n#ifdef _MSC_VER\n#pragma warning(disable:4464)\n#endif /* _MSC_VER */\n\n#include \"../CMacroExtensions/CMacroExtensions.h\"\n\n#ifdef _MSC_VER\n#pragma warning(default:4464)\n#endif /* _MSC_VER */\n\n\nINT_MAIN_ARGC_ARGV_BEGIN\n\n/* STDC and cplusplus */\n{\n#if defined(__STDC_VERSION__)\n    printf(\"__STDC_VERSION__  %ld\\n\", __STDC_VERSION__);\n#endif /* defined(__STDC_VERSION__) */\n#if defined(__cplusplus)\n    printf(\"__cplusplus       %ld\\n\", __cplusplus);\n#endif /* defined(__cplusplus) */\n    printf(\"\\n\");\n}\n\n/* Align.h */\n{\n    printf(\"Align test\\n\");\n\n    printf(\"ALIGN_UP(24, 16)   = %d\\n\", ALIGN_UP(24, 16));\n    printf(\"ALIGN_DOWN(24, 16) = %d\\n\", ALIGN_DOWN(24, 16));\n\n    printf(\"IS_ALIGNED(24, 4)  = %d\\n\", IS_ALIGNED(24, 4));\n    printf(\"IS_ALIGNED(24, 16) = %d\\n\", IS_ALIGNED(24, 16));\n\n    printf(\"ALIGN_PTR(24, 16)  = %p\\n\", ALIGN_PTR((void*)24, 16));\n\n    printf(\"ALIGN_SIZE(24, 16) = %d\\n\", ALIGN_SIZE(24, 16));\n\n    printf(\"\\n\");\n}\n\n/* ArgUsed.h */\n{\n    unsigned char uc;\n\n    printf(\"ArgUsed test\\n\");\n\n    ARG_USED(argc);\n    ARG_USED(argv);\n    ARG_USED(uc);\n\n    printf(\"\\n\");\n}\n\n/* Assert.h */\n{\n    int i;\n\n    printf(\"Assert test\\n\");\n\n    i = 2;\n    ASSERT_MESSAGE(2 == i, \"custom error message!\");\n\n    printf(\"\\n\");\n}\n\n/* BitsPerType.h */\n{\n    printf(\"BitsPerType test\\n\");\n\n    printf(\"char      Bits %zu\\n\", BITS_PER_TYPE(char));\n    printf(\"short     Bits %zu\\n\", BITS_PER_TYPE(short));\n    printf(\"int       Bits %zu\\n\", BITS_PER_TYPE(int));\n    printf(\"long      Bits %zu\\n\", BITS_PER_TYPE(long));\n#if defined(__STDC_VERSION__) \u0026\u0026 __STDC_VERSION__ \u003e= 199901L || defined(__cplusplus) \u0026\u0026 __cplusplus \u003e= 201103L\n    printf(\"long long Bits %zu\\n\", BITS_PER_TYPE(long long));\n#endif /* defined(__STDC_VERSION__) \u0026\u0026 __STDC_VERSION__ \u003e= 199901L || defined(__cplusplus) \u0026\u0026 __cplusplus \u003e= 201103L */\n\n    printf(\"\\n\");\n}\n\n/* Bool.h */\n{\n    printf(\"Bool test\\n\");\n    printf(\"GET_BOOL(10) = %d\\n\", GET_BOOL(10));\n    printf(\"GET_BOOL(0)  = %d\\n\", GET_BOOL(0));\n\n    printf(\"TRUE         = \\\"%s\\\"\\n\", BOOL_TO_STRING(TRUE));\n    printf(\"FALSE        = \\\"%s\\\"\\n\", BOOL_TO_STRING(FALSE));\n\n    printf(\"\\n\");\n}\n\n/* Cast.h */\n{\n    unsigned char byte = 1;\n    unsigned short word = 2;\n    unsigned short* usptr;\n\n    printf(\"Cast test\\n\");\n\n    byte = CAST(word, unsigned char);\n    usptr = CAST_PTR(\u0026word, unsigned short);\n\n    ARG_USED(byte);\n    ARG_USED(word);\n    ARG_USED(usptr);\n\n    printf(\"\\n\");\n}\n\n/* Concatenate.h */\n{\n    char Hello, World, HelloWorld;\n    \n    printf(\"Concatenate test\\n\");\n\n    CONCATENATE(Hello, World) = 1;\n\n    ARG_USED(Hello);\n    ARG_USED(World);\n    ARG_USED(HelloWorld);\n\n    printf(\"\\n\");\n}\n\n/* CTypeExt.h */\n{\n    printf(\"CTypeExt test\\n\");\n\n    printf(\"isascii('A')   = %d\\n\", isascii('A'));\n    printf(\"isascii(0x80)  = %d\\n\", isascii(0x80));\n    printf(\"\\n\");\n    printf(\"isbdigit('0')  = %d\\n\", isbdigit('0'));\n    printf(\"isbdigit('1')  = %d\\n\", isbdigit('1'));\n    printf(\"isbdigit('2')  = %d\\n\", isbdigit('2'));\n    printf(\"\\n\");\n    printf(\"isodigit('0')  = %d\\n\", isodigit('0'));\n    printf(\"isodigit('7')  = %d\\n\", isodigit('7'));\n    printf(\"isodigit('8')  = %d\\n\", isodigit('8'));\n    printf(\"\\n\");\n\n#if !defined(__STDC_VERSION__) || defined(__STDC_VERSION__) \u0026\u0026 __STDC_VERSION__ \u003c 199901L \n\n    printf(\"isblank(' ')   = %d\\n\", isblank(' '));\n    printf(\"isblank('\\t')  = %d\\n\", isblank('\\t'));\n    printf(\"isblank('0')   = %d\\n\", isblank('0'));\n    printf(\"\\n\");\n\n#endif /* !defined(__STDC_VERSION__) || defined(__STDC_VERSION__) \u0026\u0026 __STDC_VERSION__ \u003c 199901L  */\n\n    /* char to ascii */\n    printf(\"toascii(0x130) = '%c'\\n\", toascii(0x130));\n    printf(\"\\n\");\n\n    printf(\"\\n\");\n}\n\n/* Datatype.h */\n{\n    UINT32 ui32 = 0x12345678L;\n    ULONG ul32 = 0L;\n\n    printf(\"Datatype test\\n\");\n\n    ul32 = ui32;\n\n    ARG_USED(ul32);\n\n    printf(\"\\n\");\n}\n\n/* DatatypeCpu.h */\n{\n    printf(\"DatatypeCpu test\\n\");\n\n    printf(\"\\n\");\n}\n\n/* DatatypeWin.h */\n{\n    BYTE byte;\n    WORD word;\n    DWORD dword;\n#if defined(__STDC_VERSION__) \u0026\u0026 __STDC_VERSION__ \u003e= 199901L \n    QWORD qword;\n#endif /*  defined(__STDC_VERSION__) \u0026\u0026 __STDC_VERSION__ \u003e= 199901L */\n\n    printf(\"DatatypeWin test\\n\");\n\n    byte = MAKEBYTE(0x1, 0x2);\n    printf(\"BYTE        = %02X\\n\", byte);\n    printf(\"HINIBBLE    = %01X\\n\", (BYTE)HINIBBLE(byte));\n    printf(\"LONIBBLE    = %01X\\n\", (BYTE)LONIBBLE(byte));\n    printf(\"\\n\");\n\n    word = MAKEWORD(0x12, 0x34);\n    printf(\"WORD        = %04X\\n\", word);\n    printf(\"HIBYTE      = %02X\\n\", (BYTE)HIBYTE(word));\n    printf(\"LOBYTE      = %02X\\n\", (BYTE)LOBYTE(word));\n    printf(\"\\n\");\n\n    dword = MAKEDWORD(0x1234, 0x5678);\n    printf(\"DWORD       = %08lX\\n\", (unsigned long)dword);\n    printf(\"HIWORD      = %04X\\n\", (WORD)HIWORD(dword));\n    printf(\"LOWORD      = %04X\\n\", (WORD)LOWORD(dword));\n    printf(\"\\n\");\n\n#if defined(__STDC_VERSION__) \u0026\u0026 __STDC_VERSION__ \u003e= 199901L \n\n    qword = MAKEQWORD(0x12345678ll, 0x9ABCDEF0ll);\n    printf(\"QWORD       = %016llX\\n\", qword);\n    printf(\"HIDWORD     = %08X\\n\", (DWORD)HIDWORD(qword));\n    printf(\"LODWORD     = %08X\\n\", (DWORD)LODWORD(qword));\n    printf(\"\\n\");\n\n#endif /*  defined(__STDC_VERSION__) \u0026\u0026 __STDC_VERSION__ \u003e= 199901L */\n\n    printf(\"\\n\");\n}\n\n/* Debug.h */\n{\n    printf(\"Debug test\\n\");\n\n    DEBUG_MESSAGE(\"debug message\");\n\n    printf(\"\\n\");\n}\n\n/* Dump.h */\n{\n    unsigned char ucStr[] = \"abc\";\n\n    printf(\"Dump test\\n\");\n\n    PRINT_VARIABLE((int)1);\n    PRINT_VARIABLE_U((unsigned int)1);\n\n    PRINT_VARIABLE_L((long)1L);\n    PRINT_VARIABLE_UL((unsigned long)1L);\n\n#if defined(__STDC_VERSION__) \u0026\u0026 __STDC_VERSION__ \u003e= 199901L \n    PRINT_VARIABLE_LL((long long)1LL);\n    PRINT_VARIABLE_ULL((unsigned long long)1LL);\n#endif\n\n    PRINT_VARIABLE_SIZE_T((size_t)1);\n\n    PRINT_POINTER((void*)ucStr);\n\n    PRINT_STRING(ucStr);\n\n    printf(\"\\n\");\n}\n\n/* Exclude.h */\n{\n    printf(\"Exclude test\\n\");\n\n    EXCLUDE_FROM_BUILD(\n        printf(\"abc\\n\");\n        printf(\"def\\n\");\n        printf(\"ghi\\n\");\n        );\n\n    EXCLUDE_FROM_RUNTIME(0,\n        printf(\"123\\n\");\n        printf(\"456\\n\");\n        printf(\"789\\n\");\n        );\n\n    printf(\"\\n\");\n}\n\n/* File.h */\n#if defined(__clang__)\n#pragma clang unsafe_buffer_usage begin\n#endif /* defined(__clang__) */\n{\n    printf(\"File test\\n\");\n\n    printf(\"FILE_SEPARATOR = '%c'\\n\", FILE_SEPARATOR);\n\n    printf(\"FILE_SHORT = %s\\n\", FILE_SHORT);\n\n    printf(\"\\n\");\n}\n#if defined(__clang__)\n#pragma clang unsafe_buffer_usage end\n#endif /* defined(__clang__) */\n\n/* Func.h */\n{\n    func__(\"main\");\n\n    printf(\"Func test\\n\");\n\n    printf(\"%s\\n\", FUNC_NAME(__func__));\n\n    printf(\"\\n\");\n}\n\n/* Member.h */\n{\n    struct abc { int a; short b; short c; };\n\n    printf(\"Member test\\n\");\n\n    printf(\"MEMBER_SIZEOF(abc, a)      = %zu\\n\", MEMBER_SIZEOF(struct abc, a));\n    printf(\"MEMBER_SIZEOF(abc, b)      = %zu\\n\", MEMBER_SIZEOF(struct abc, b));\n    printf(\"MEMBER_SIZEOF(abc, c)      = %zu\\n\", MEMBER_SIZEOF(struct abc, c));\n    printf(\"\\n\");\n\n    printf(\"MEMBER_OFFSETOF(abc, a)    = %zu\\n\", MEMBER_OFFSETOF(struct abc, a));\n    printf(\"MEMBER_OFFSETOF(abc, b)    = %zu\\n\", MEMBER_OFFSETOF(struct abc, b));\n    printf(\"MEMBER_OFFSETOF(abc, c)    = %zu\\n\", MEMBER_OFFSETOF(struct abc, c));\n    printf(\"\\n\");\n\n    printf(\"MEMBER_OFFSETOFEND(abc, c) = %zu\\n\", MEMBER_OFFSETOFEND(struct abc, c));\n\n    printf(\"\\n\");\n}\n\n/* Paste.h */\n{\n    printf(\"Paste test\\n\");\n\n    printf(\"str + ing = %s\\n\", PASTE(\"str\", \"ing\"));\n\n    printf(\"\\n\");\n}\n\n/* StdargExt.h */\n{\n    printf(\"StdargExt test\\n\");\n\n    printf(\"\\n\");\n}\n\n/* Stringify.h */\n{\n    int variable = 5;\n\n    printf(\"Stringify test\\n\");\n\n    printf(\"var = \\\"%s\\\" = %d\\n\", STRINGIFY(variable), variable);\n\n    printf(\"\\n\");\n}\n\n/* Swap.h */\n{\n    long long1 = 5;\n    long long2 = 7;\n#if defined(__STDC_VERSION__) \u0026\u0026 __STDC_VERSION__ \u003e= 199901L \n    long long longlong1 = 5;\n    long long longlong2 = 7;\n#endif\n\n    printf(\"Swap test\\n\");\n\n    printf(\"%s = %ld\\n\", STRINGIFY(long1), long1);\n    printf(\"%s = %ld\\n\", STRINGIFY(long2), long2);\n    SWAP(long1, long2);\n    printf(\"after SWAP\\n\");\n    printf(\"%s = %ld\\n\", STRINGIFY(long1), long1);\n    printf(\"%s = %ld\\n\", STRINGIFY(long2), long2);\n\n#if defined(__STDC_VERSION__) \u0026\u0026 __STDC_VERSION__ \u003e= 199901L \n    printf(\"%s = %lld\\n\", STRINGIFY(longlong1), longlong1);\n    printf(\"%s = %lld\\n\", STRINGIFY(longlong2), longlong2);\n    SWAP(longlong1, longlong2);\n    printf(\"after SWAP\\n\");\n    printf(\"%s = %lld\\n\", STRINGIFY(longlong1), longlong1);\n    printf(\"%s = %lld\\n\", STRINGIFY(longlong2), longlong2);\n#endif\n\n    printf(\"\\n\");\n}\n\n/* Trace.h */\n{\n    printf(\"Trace test\\n\");\n\n    TRACE_MESSAGE(\"trace message\");\n\n    printf(\"\\n\");\n}\n\nreturn(0);\n\nINT_MAIN_ARGC_ARGV_END\n```\n\n\n# History of changes ...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fignackocom%2Fcmacroextensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fignackocom%2Fcmacroextensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fignackocom%2Fcmacroextensions/lists"}