cancel
Showing results for 
Search instead for 
Did you mean: 

I maked a macro in c, that can process in vscode with GNU11 standard, when process in cubeIDE, error.

luke gong
Associate II

#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)

1 REPLY 1
luke gong
Associate II

The main purpose of this macro is to print the array