Added generic daPush macro and removed unused macros

This commit is contained in:
Maciej Samborski 2024-10-12 14:42:24 +02:00
parent cadebd77ff
commit 6413a9c95c
2 changed files with 19 additions and 20 deletions

7
da.h
View File

@ -43,9 +43,10 @@ void daBzero(dynarr da);
#define dynarr(type) type * #define dynarr(type) type *
#define daCreate(type, cap) _daCreate(cap, sizeof(type), 0) #define daCreate(type, cap) _daCreate(cap, sizeof(type), 0)
#define daPush(da, item) _daPush((void *)&da, &item) #define daPush(da, item) _Generic((item), \
#define daPushLit(da, item) _daPushLit((void *)&da, item) char *: _daPushStr, \
#define daPushStr(da, str) _daPushStr((void *)&da, str) default: _daPushLit \
)((void *)&da, item)
#define daPop(da, item) _daPop(da, &item) #define daPop(da, item) _daPop(da, &item)
#endif // DA_H_ #endif // DA_H_

View File

@ -1,5 +1,3 @@
#include <stdio.h>
#define DA_IMPLEMENTATION #define DA_IMPLEMENTATION
#include "da.h" #include "da.h"
@ -49,13 +47,13 @@ int main(void)
dynarr(unsigned short) da = resultGeneric(dynarr(unsigned short), gr); dynarr(unsigned short) da = resultGeneric(dynarr(unsigned short), gr);
daPushLit(da, 69); daPush(da, 69);
daPushLit(da, 420); daPush(da, 420);
daPushLit(da, 1337); daPush(da, 1337);
daPushLit(da, 34); daPush(da, 34);
daPushLit(da, 35); daPush(da, 35);
daPushLit(da, 1667); daPush(da, 1667);
unsigned short x = 0; unsigned short x = 0;
@ -72,14 +70,14 @@ int main(void)
dynarr(char) da2 = daCreate(char, 1).val; dynarr(char) da2 = daCreate(char, 1).val;
daPushLit(da2, 'H'); daPush(da2, 'H');
daPushLit(da2, 'i'); daPush(da2, 'i');
daPushLit(da2, ' '); daPush(da2, ' ');
daPushLit(da2, 'm'); daPush(da2, 'm');
daPushLit(da2, 'o'); daPush(da2, 'o');
daPushLit(da2, 'm'); daPush(da2, 'm');
daPushLit(da2, '?'); daPush(da2, '?');
daPushLit(da2, '?'); daPush(da2, '?');
*(char *)daGetRef(da2, 6) = '!'; *(char *)daGetRef(da2, 6) = '!';
@ -96,7 +94,7 @@ int main(void)
dynarr(char *) da3 = daCreate(char *, 1).val; dynarr(char *) da3 = daCreate(char *, 1).val;
for (size_t i = 0; i < 1000000; ++i) { for (size_t i = 0; i < 1000000; ++i) {
daPushStr(da3, "Test"); daPush(da3, "Test");
} }
char * str; char * str;