]> www.git.momoyon.org Git - commonlib.git/commitdiff
[commonlib.h] Fix some prefix errors...
authorahmedsamyh <ahmedsamyh10@gmail.com>
Sun, 26 Jan 2025 12:42:42 +0000 (17:42 +0500)
committerahmedsamyh <ahmedsamyh10@gmail.com>
Sun, 26 Jan 2025 12:42:42 +0000 (17:42 +0500)
- [commonlib.h] Remove DEFINE_DYNAMIC_ARRAY() macro.

commonlib.h

index f05281286a0e4c809ecb7231e9c46be9143bf8eb..1381b0d35dcd17c66d0500ac546e4f6368c8277c 100644 (file)
@@ -91,24 +91,34 @@ typedef struct c_Arena c_Arena;
 \r
 // NOTE: To use c_da_append() the Dynamic-Array struct should be defined using\r
 // DEFINE_DYNAMIC_ARRAY or have the same members as below!\r
-#define DEFINE_DYNAMIC_ARRAY(struct_name, elm_type) typedef struct {\\r
-        elm_type *items;\\r
-        size_t count;\\r
-        size_t capacity;\\r
-    }\r
+// NOTE!!!: We actually don't want this since this makes the user want to \r
+// use this macro to define dynamic arrays. But the user might want extra fields\r
+// in the struct; So we recommend defining da structs manually like:\r
+// ```C\r
+// typedef struct {\r
+//    <item-type> items;\r
+//    size_t count;\r
+//    size_t capacity;\r
+//    [extra fields...];\r
+// }\r
+// ```\r
+// #define DEFINE_DYNAMIC_ARRAY(struct_name, elm_type) typedef struct {\\r
+//         elm_type *items;\\r
+//         size_t count;\\r
+//         size_t capacity;\\r
+//     }\r
 \r
 #define c_DYNAMIC_ARRAY_INITIAL_CAPACITY (sizeof(size_t))\r
 \r
 #define c_da_append(da, elm) do {\\r
                if ((da).items == NULL) {\\r
-                       (da).capacity = DYNAMIC_ARRAY_INITIAL_CAPACITY;\\r
+                       (da).capacity = c_DYNAMIC_ARRAY_INITIAL_CAPACITY;\\r
                        (da).count = 0;\\r
                        (da).items = C_MALLOC(sizeof(elm) * (da).capacity);\\r
                }\\r
                if ((da).count + 1 > (da).capacity) {\\r
                        (da).capacity *= 2;\\r
-                       if (DEBUG) log_info("%s realloced!", #da);\\r
-                       ASSERT(C_REALLOC((da).items, (da).capacity * sizeof(*(da).items)) != NULL, "TODO: Log error instead of asserting");\\r
+                       c_ASSERT(C_REALLOC((da).items, (da).capacity * sizeof(*(da).items)) != NULL, "TODO: Log error instead of asserting");\\r
                }\\r
                (da).items[(da).count++] = elm;\\r
        } while (0)\r