|
Tom Delany wrote: event that the code is ever ported to a big-endian system, it would be completely broken.
No it wouldn't.
The code POSTED would work regardless of that.
As mentioned it is a TCP stream so it sequential. The switch statement is using ascii. The only way endianess would matter would be if the stream started to use a different character set. And if it did that it would fail if
1. The character system was not using a 8 bit lower representation of that matched ascii (UTF8 does where UTF16 does not.)
2. AND if the protocol changed.
And certainly if item 2 is true then all sorts of problems could result. Such as the rest of the code, following the switch, failing as well.
|
|
|
|
|
That's how you handle tags in ICC profiles, for example. It's a perfectly reasonable thing to do.
Tom Delany wrote: WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
Still one of my favorite sigs on CP.
Software Zen: delete this;
|
|
|
|
|
No endian-sensitive code (which includes all multibyte chars) is "perfectly sensible".
|
|
|
|
|
'Sensibility' of a particular approach always depends upon the problem being solved. Making code endian-insensitive is necessary only if you plan on porting it between different endian environments.
Software Zen: delete this;
|
|
|
|
|
I suppose he didn't liked If - else- ifs...
|
|
|
|
|
It's sort of both... it'd be properly brilliant if the "verb =" line were commented...
|
|
|
|
|
Tom Delany wrote: This is either brilliant, or just bloody awful.
What is the fourth character of the protocol?
Tom Delany wrote: I'm coming down on the side of "bloody awful":
How would you refactor it?
|
|
|
|
|
In my eyes it is ugly, but one of the easies way to compare strings (up to 8 bytes) in a most efficient way.
If it's needed and documented ... ok.
I recently saw a very strange way to copy an object in C++:
- the class defines all its data member attributes within 64 Byte
- the data member attributes are ordered to use alignment efficently
- copying the class is done this way (or similar)
C64bitClass src, dst;
__int64 *pnSrc = static_cast<__int64*>(&src);
__int64 *pnDst = static_cast<__int64*>(&dst);
*pnDst = *pnSrc;
This really ugly, isn't it!
|
|
|
|