From ccfea01d2409e357e0eba47b05be5687a23dbae5 Mon Sep 17 00:00:00 2001 From: OusmBlueNinja <89956790+OusmBlueNinja@users.noreply.github.com> Date: Tue, 24 Dec 2024 10:54:40 -0600 Subject: [PATCH] Create example.c --- example.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 example.c diff --git a/example.c b/example.c new file mode 100644 index 0000000..807fd0b --- /dev/null +++ b/example.c @@ -0,0 +1,56 @@ +#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; +} \ No newline at end of file