In C, a typedef doesn't grant you any additional type safety. You can use the the new type any place you can use the old type. Sometimes that's what I want, and sometimes it is not. Sometimes I want the compiler to warn me if I misuse my new type.
To make that happen, I sometimes do something like this:
typedef struct {
int value;
} NewType;
NewType doSomethingNT(NewType a, NewType b) {
return a.value + b.value;
}
Compared to:
int doSomethingI(int a, int b) {
return a + b;
}
(That plus is just an example. Let's assume that either there's a function call overhead in both cases, or else I ask the function to be inlined in both cases. But let's not compare doSomethingNT to the bare + operator, obviously the latter is faster because it doesn't have the function call overhead)
I guess I'm asking, is there any overhead in "boxing" a primitive type a one element struct, but using that struct as a value type. (I.e. I'm not calling malloc and using pointers to it like how boxing works in Java.)