Is there a good way to force type incompatibility in C?

后端 未结 2 1313
孤城傲影
孤城傲影 2021-01-21 14:05

For purposes of type checking I would like to define a function on the lines of

void myfunc(type1 a, type2 b)
{
...
}

where type1

2条回答
  •  [愿得一人]
    2021-01-21 15:05

    You could wrap the two types in a Struct.

    typedef struct {
        uint8_t data;
    } type1;
    
    typedef struct {
        uint8_t data;
    } type2;
    

    Edit: I don't like it because you now have to use a.data instead of a

提交回复
热议问题