Create a C function that accepts parameters of different data types

前端 未结 6 1269
陌清茗
陌清茗 2021-02-09 02:07

I\'m relatively new to the C programming language, and I\'m trying to figure out how to create a function that can accept different types of data as parameters. The function is

6条回答
  •  逝去的感伤
    2021-02-09 03:09

    It's not really possible, but you can make a tagged union

    typedef struct {
        union {
            ssize_t i;
            double d;
            char *s;
        } unknown;
        char select;
    } Dynamic;
    
    

    Or you can use a void pointer:

    typedef struct {
      void * unknown;
      char identity;
    } Dynamic;
    

提交回复
热议问题