2022-12-14 12:45 AM
#define PRINTARRAYSET(type, name) void printArray_##name(type* arr, size_t size) {\
for (size_t i = 0; i < size; i++)\
printf("%d, ",arr[i]);\
printf("\r\n");\
}
#define PRINTARRAYSETLONG(type, name) void printArray_##name(type* arr, size_t size) {\
for (size_t i = 0; i < size; i++)\
printf("%ld, ",arr[i]);\
printf("\r\n");\
}
#define PRINTARRAYSETFLOAT(type, name) void printArray_##name(type* arr, size_t size) {\
for (size_t i = 0; i < size; i++)\
printf("%f, ",arr[i]);\
printf("\r\n");\
}
PRINTARRAYSET(char , char)
PRINTARRAYSET(signed char ,signed_char)
PRINTARRAYSET(short int , short_int)
PRINTARRAYSET(int , int)
PRINTARRAYSETLONG(long , long)
PRINTARRAYSET(unsigned char , unsigned_char)
PRINTARRAYSET(unsigned int , unsigned_int)
PRINTARRAYSET(short unsigned int , short_unsigned_int)
PRINTARRAYSETLONG(long unsigned int , unsigned_long)
PRINTARRAYSETFLOAT(float , float)
PRINTARRAYSETFLOAT(double , double)
#define PRINTARRAY(arr, size) _Generic(arr,\
char*: printArray_char,\
signed char*: printArray_signed_char,\
short int*: printArray_short_int,\
int*: printArray_int,\
long*: printArray_long,\
unsigned char*: printArray_unsigned_char,\
short unsigned int*: printArray_short_unsigned_int,\
unsigned int*: printArray_unsigned_int,\
unsigned long*: printArray_unsigned_long,\
float*: printArray_float,\
double*: printArray_double\
)(arr, size)
2022-12-14 12:45 AM
The main purpose of this macro is to print the array