Re:Your test suite is trying to tell you something
by dllthomas on Wednesday July 03, 2013 @11:25AM
(#5985132)
I highly recommend doing this kind of thing, incidentally. Just because two things have the same backing representation does not mean they're of the same type, and wrapping in a struct tells the compiler to keep them separate. It doesn't have any impact on performance; C structs don't carry anything more than their member and you've only got the one member. I do this with indexes and ids as well.
[ Parent
| on HN ]
Re:Your test suite is trying to tell you something
by gohrt on Wednesday July 03, 2013 @11:32AM
(#5985189)
One would hope that 'typedef' would define a type in C, protecting the programmer from silent incorrect casts, but of course it doesn't, because C hates programmers.
Re:Your test suite is trying to tell you something
by dllthomas on Wednesday July 03, 2013 @11:37AM
(#5985234)
Well, typedef "defines a type", but (unfortunately) in a purely syntactic sense. If you're using typedef for something that's not wrapped in a struct or union, think hard about whether you mightn't want to also do that.