gcml/example.c
2024-12-24 10:54:40 -06:00

56 lines
1.2 KiB
C

#define DEBUG 1
#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
DEBUG_PRINT("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;
}