Last active
February 3, 2022 10:17
-
-
Save kisssko/2583277028fe4aa163b49eac89c3403d to your computer and use it in GitHub Desktop.
Universal useful macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _MISC_MACROS_H_ | |
#define _MISC_MACROS_H_ | |
#define _SET_BIT(V,B) (V) |= (1 << (B)) | |
#define _CLR_BIT(V,B) (V) &= ~(1 << (B)) | |
#define _INV_BIT(V,B) (V) ^= (1 << (B)) | |
#define NIBBLE_PAIR(LN,HN) (((LN) << 0) | ((HN) << 4)) | |
#define PRINT_TYPE_SZ(T) printf("sizeof(%s)=%u\n", #T, sizeof(T)) | |
#define TYPEMASK(T) (sizeof(T) - 1) | |
#define MASK(BITS) ((1UL << (BITS)) - 1UL) | |
#define MASK_3BITS MASK(3) | |
#define MASK_4BITS MASK(4) | |
#define MASK_5BITS MASK(5) | |
#define MASK_6BITS MASK(6) | |
#define MASK_7BITS MASK(7) | |
#define MASK_8BITS MASK(8) | |
#define MASK_16BITS MASK(16) | |
// (V)ar, (T)ype; | |
#define ALIGN_BY_TYPE(V,T) do{if(V & TYPEMASK(T)){ \ | |
V &= ~TYPEMASK(T); \ | |
V += sizeof(T);}}while(0) | |
#ifndef TRUE | |
#define TRUE true | |
#endif | |
#ifndef FALSE | |
#define FALSE false | |
#endif | |
#if EOL_IS_CRLF | |
#define EOL "\r\n" | |
#define EOL2 "\r\n\n" | |
#define EOL3 "\r\n\n\n" | |
#define EOL4 "\r\n\n\n\n" | |
#define EOL5 "\r\n\n\n\n\n" | |
#define EOL6 "\r\n\n\n\n\n\n" | |
#define EOL7 "\r\n\n\n\n\n\n\n" | |
#define EOL8 "\r\n\n\n\n\n\n\n\n" | |
#define EOL9 "\r\n\n\n\n\n\n\n\n\n" | |
#define EOL10 "\r\n\n\n\n\n\n\n\n\n\n" | |
#else | |
#define EOL "\n" | |
#define EOL2 "\n\n" | |
#define EOL3 "\n\n\n" | |
#define EOL4 "\n\n\n\n" | |
#define EOL5 "\n\n\n\n\n" | |
#define EOL6 "\n\n\n\n\n\n" | |
#define EOL7 "\n\n\n\n\n\n\n" | |
#define EOL8 "\n\n\n\n\n\n\n\n" | |
#define EOL9 "\n\n\n\n\n\n\n\n\n" | |
#define EOL10 "\n\n\n\n\n\n\n\n\n\n" | |
#endif | |
#define CLS "\033[2J\033[0;0H" | |
#endif // _MISC_MACROS_H_ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment