C の 60 トレースの汎用動的配列 Posted on February 28, 2023 By 📢 𝕄𝕊𝕄™ #pragma 出来るだけ早く#明確化 DYN_ARR_OF(種類) struct {バラエティ*レコード; 多様性 *endptr; uint32_t 能力;}#もしも !outlined(__cplusplus)#明確化 decltype( x) void*#endif#明確にする DYN_ARR_RESET(a, c) { a.records=(decltype (a.records))malloc(sizeof(a.records ) c); a.endptr=a.records ; a.能力=c;}#明確にする DYN_ARR_RESIZE (として) { uint32_t 次元=(s); もしも (a.能力 <サイズ) { a.データ=(decltype(a.データ))realloc(a.データ, sizeof(a 。データ ) サイズ); a. )容量=サイズ; } a.endptr=a.データ + サイズ;}#define DYN_ARR_DESTROY(a) if (a.data !=NULL) { free(a.データ); a.データ=a. endptr=NULL;}#定義 DYN_ARR_APPEND(a, v) { ) ptrdiff_t cur_size=a .endptr – a.データ; 主張する(cur_size>=0); if ((size_t)cur_size>=a.能力) { a.能力 <<=1u ;𝚆𝚊𝚝𝚌𝚑 𝙽𝙾𝚆 📺 Artificial intelligence, Ask HN, Dynamic, generic, Show HN, Technology, TOP HN Tags:Dynamic, generic, Show NH: