网站首页HOME
荣塘镇荣塘镇
温水乡温水乡
铜星乡铜星乡
喜神乡喜神乡
班仁乡班仁乡
锡城镇锡城镇
C语言中的「泛型」编程,这个代码是我在使用惯了C++之后转头想看C语言的优雅方式怎么做的时候找到的。
虽然比不上C++的真泛型,但是比我想象的好很多。
#include #include #include // 定义泛型容器宏 #define DEFINE_VECTOR(T) \ typedef struct { \ T* data; \ size_t size; \ size_t capacity; \ } vector_##T; \ \ vector_##T vector_##T##_create() { \ vector_##T v; \ v.data = NULL; \ v…。