D enums != type safety
Posted by randomz on June 28, 2006
I’ll post here the last post from my old coding blog, since I just wrote it a couple of minutes ago:
Copy & Paste struck on me again, as it often does. I had written a function to take a Sofu.Encoding.Encoding enum value (which is one of the possible Unicode encodings) and return the endianness that will be used by that encoding, as an Endian enum value.
However, I had pasted this from code that used std.stream’s BOM enum type. So, I had written:
switch(encoding) {
case BOM.UTF16LE: case BOM.UTF32LE: return Endian.LittleEndian;
[...]
Of course, I should have written
switch(encoding) {
case Encoding.UTF16LE: case Encoding.UTF32LE: return Endian.LittleEndian;
This actually caused little and big endian to be exactly reversed.
I guess this is a serious downside of having the enums be actual int variables. The compiler wasn’t able to see that I was comparing an Encoding enum value to a BOM enum value.
Oh, and BTW, the SDL_mixer bug has been fixed and I was able to check the new DLLs into the Evilness SVN. ![]()
(Not that anything has changed over the old version…)