Some C and C++ Utility macros and functions
Docs.md | ||
example.c | ||
gcml.h | ||
README.md |
GCML
A comprehensive collection of essential C and C++ utility macros designed to streamline your development workflow. Enhance your code with powerful tools for debugging, logging, memory management, bit manipulation, and more.
📄 Documentation
Dive into the full documentation here.
🔧 Usage Example
Below is a single example demonstrating the usage of several common macros provided by gcml
. This example includes logging, memory management, bit manipulation, assertions, and looping constructs.
#include "gcml.h"
typedef struct {
int id;
char name[50];
} Person;
DEPRECATED("Use new_function() instead.")
void old_function() {
LOG_WARN("This function is deprecated.");
}
int main() {
// Logging
LOG_INFO("Application started.");
// Memory Management
int *numbers = NULL;
SAFE_MALLOC(numbers, sizeof(int) * 5);
for(int i = 0; i < 5; ++i) {
numbers[i] = i * i;
}
LOG_INFO("Allocated numbers array.");
// Bit Manipulation
unsigned int flags = 0;
SET_BIT(flags, 1);
LOG_INFO("Flags after setting bit 1: %u", flags);
if (CHECK_BIT(flags, 1)) {
LOG_INFO("Bit 1 is set.");
}
TOGGLE_BIT(flags, 1);
LOG_INFO("Flags after toggling bit 1: %u", flags);
// Assertions
ASSERT(numbers != NULL, "Memory allocation failed for numbers.");
// Loop Constructs
int arr[] = {10, 20, 30, 40, 50};
int *item;
FOREACH(item, arr) {
LOG_INFO("Array element: %d", *item);
}
// Using Deprecated Function
old_function();
// Cleanup
SAFE_FREE(numbers);
LOG_INFO("Memory freed. Application exiting.");
return 0;
}
📝 License
This project is licensed under the MIT License.
Feel free to contribute by opening issues or submitting pull requests. For more details, refer to the documentation.