Search code examples
cipc-preprocessorlow-level

C. Pass the #predefined list of arguments to function


In C there is the way to initialize array or struct with predefined list of values:

#define STRUCT_DUMMY_VAL1  "dummy", 21, 2.3
struct dummy d = {STRUCT_DUMMY_VAL1};

#define INT_ARRAY_VAL1     1,2,3
int a[] = {INT_ARRAY_VAL1};

Is there the way to pass the predefined list of arguments to function?

#define IP_ADDR  192,168,3,3
ip_addr_assemble(u8_t,u8_t,u8_t,u8_t);
void dosmth(){
    u32_t ip = ip_addr_assemble(IP_ADDR);  // Compile error
}

Solution

  • No problem with such code. GCC ate it without any warnings. The problem is with my compilier. You can test on ideone https://ideone.com/ 0VIkz5