Click here to Skip to main content
14,363,281 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Let's "switch" to Something Else Pin
OriginalGriff3-Apr-13 7:25
protectorOriginalGriff3-Apr-13 7:25 
GeneralRe: Let's "switch" to Something Else Pin
Tom Delany3-Apr-13 9:02
memberTom Delany3-Apr-13 9:02 
GeneralRe: Let's "switch" to Something Else Pin
OriginalGriff3-Apr-13 9:14
protectorOriginalGriff3-Apr-13 9:14 
GeneralRe: Let's "switch" to Something Else Pin
BobJanova4-Apr-13 0:27
memberBobJanova4-Apr-13 0:27 
GeneralRe: Let's "switch" to Something Else Pin
jibalt5-Apr-13 20:20
memberjibalt5-Apr-13 20:20 
GeneralRe: Let's "switch" to Something Else Pin
BobJanova8-Apr-13 1:48
memberBobJanova8-Apr-13 1:48 
GeneralRe: Let's "switch" to Something Else Pin
jibalt9-Apr-13 0:42
memberjibalt9-Apr-13 0:42 
GeneralRe: Let's "switch" to Something Else Pin
BobJanova10-Apr-13 0:23
memberBobJanova10-Apr-13 0:23 
You can use big words all you like, but either 'CMD ' is endian sensitive, i.e. it is the byte stream 'C', 'M', 'D', ' ' on one system and ' ', 'D', 'M', 'C' on another, or it isn't, i.e. it's always 'C', 'M', 'D', ' ' and therefore maps to a different integer.

In the first case, *recv won't be correct because the byte stream you're checking for is always the same, but the code in the original example would be, because it manually makes the integer in the big-endian manner, and that will be the value that the constant has if it switches the byte order. And if not, *recv will be correct, even if the integer interpretation of that value will be different.

There is one good argument you could have deployed, which is that the standard doesn't actually define whether a multi character constant refers to byte order or integer value. But if it has a consistent meaning in real world compilers, that doesn't really matter.
GeneralRe: Let's "switch" to Something Else Pin
jibalt10-Apr-13 7:33
memberjibalt10-Apr-13 7:33 
GeneralRe: Let's "switch" to Something Else Pin
Rob Grainger9-Apr-13 3:59
memberRob Grainger9-Apr-13 3:59 
GeneralRe: Let's "switch" to Something Else Pin
jschell9-Apr-13 10:05
memberjschell9-Apr-13 10:05 
GeneralRe: Let's "switch" to Something Else Pin
jibalt10-Apr-13 7:34
memberjibalt10-Apr-13 7:34 
GeneralRe: Let's "switch" to Something Else Pin
jschell10-Apr-13 9:17
memberjschell10-Apr-13 9:17 
GeneralRe: Let's "switch" to Something Else Pin
jibalt25-Apr-13 16:44
memberjibalt25-Apr-13 16:44 
GeneralRe: Let's "switch" to Something Else Pin
NAANsoft9-Apr-13 2:25
memberNAANsoft9-Apr-13 2:25 
GeneralRe: Let's "switch" to Something Else Pin
Rob Grainger9-Apr-13 4:01
memberRob Grainger9-Apr-13 4:01 
GeneralRe: Let's "switch" to Something Else Pin
NAANsoft9-Apr-13 5:23
memberNAANsoft9-Apr-13 5:23 
GeneralRe: Let's "switch" to Something Else Pin
jschell9-Apr-13 10:03
memberjschell9-Apr-13 10:03 
GeneralRe: Let's "switch" to Something Else Pin
Gary Wheeler4-Apr-13 1:47
memberGary Wheeler4-Apr-13 1:47 
GeneralRe: Let's "switch" to Something Else Pin
jibalt5-Apr-13 20:21
memberjibalt5-Apr-13 20:21 
GeneralRe: Let's "switch" to Something Else Pin
Gary Wheeler8-Apr-13 1:11
memberGary Wheeler8-Apr-13 1:11 
GeneralRe: Let's "switch" to Something Else Pin
ClockMeister9-Apr-13 2:52
professionalClockMeister9-Apr-13 2:52 
GeneralRe: Let's "switch" to Something Else Pin
RafagaX9-Apr-13 5:56
professionalRafagaX9-Apr-13 5:56 
GeneralRe: Let's "switch" to Something Else Pin
Dan Sutton9-Apr-13 7:34
memberDan Sutton9-Apr-13 7:34 
GeneralRe: Let's "switch" to Something Else Pin
jschell9-Apr-13 10:08
memberjschell9-Apr-13 10:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.