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

后端 未结 2 1314
孤城傲影
孤城傲影 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:00

    I think you can wrap your types using struct and then pass pointer to these structs.

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题