Click here to Skip to main content
15,924,507 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: Ugh Pin
Steve Hansen14-May-08 2:26
Steve Hansen14-May-08 2:26 
GeneralRe: Ugh Pin
ToreUp14-May-08 4:35
ToreUp14-May-08 4:35 
GeneralIs this a horror? [modified] Pin
Gary R. Wheeler10-May-08 2:12
Gary R. Wheeler10-May-08 2:12 
GeneralRe: Is this a horror? Pin
CPallini10-May-08 3:47
mveCPallini10-May-08 3:47 
GeneralRe: Is this a horror? Pin
asrelu10-May-08 18:52
asrelu10-May-08 18:52 
GeneralRe: Is this a horror? Pin
Gary R. Wheeler11-May-08 1:18
Gary R. Wheeler11-May-08 1:18 
GeneralRe: Is this a horror? Pin
PIEBALDconsult12-May-08 4:57
mvePIEBALDconsult12-May-08 4:57 
GeneralRe: Is this a horror? Pin
supercat912-May-08 16:49
supercat912-May-08 16:49 
I believe that in C, typecasting or type-coercing a constant zero into a pointer is guaranteed to yield a null pointer, regardless of an architecture's actual storage of such things. Likewise, a null pointer is guaranteed to compare equal to a constant zero, and a non-null pointer is guaranteed to declare non-equal.

This does not imply that architectures have to actually store a value of zero for the null. It would be perfectly acceptable for an architecture to subtract one from an integer when casting to a pointer, and add one when casting back (so a null pointer would be stored as 0xFFFFFFFF). On some architectures there may be some significant advantages to doing so (e.g. if logical address 0x00000000 happened to be the start of user data space, or if an access to 0xFFFFFFFF would generate a hardware trap but 0x00000000 would not).

It's important to realize that C is actually very open-ended about certain implementation details. While the existence of bit-wise operators and the requirement that (-a)==(~a+1) would suggest that a machine that uses binary two's complement arithmetic would be desirable, it would nonetheless be possible to produce a fully-conforming implementation on hardware that used BCD for all math. The bit-wise operators would be extraordinarily slow on such a machine, but if the compiler's generated code produced correct results the implementation would be standards-compliant.
GeneralRe: Is this a horror? Pin
Vishnu Rana14-May-08 21:18
Vishnu Rana14-May-08 21:18 
GeneralRe: Is this a horror? Pin
asrelu17-May-08 16:21
asrelu17-May-08 16:21 
GeneralRe: Is this a horror? Pin
Gary R. Wheeler18-May-08 0:41
Gary R. Wheeler18-May-08 0:41 
GeneralRe: Is this a horror? Pin
Tony Wesley3-Jun-08 11:16
Tony Wesley3-Jun-08 11:16 
GeneralRe: Is this a horror? Pin
CPallini14-May-08 21:41
mveCPallini14-May-08 21:41 
GeneralRe: Is this a horror? [modified] Pin
asrelu17-May-08 16:41
asrelu17-May-08 16:41 
GeneralRe: Is this a horror? Pin
CPallini18-May-08 6:08
mveCPallini18-May-08 6:08 
JokeRe: Is this a horror? Pin
Mladen Janković10-May-08 23:20
Mladen Janković10-May-08 23:20 
GeneralRe: Is this a horror? Pin
John R. Shaw13-May-08 7:47
John R. Shaw13-May-08 7:47 
GeneralRe: Is this a horror? Pin
Gary R. Wheeler13-May-08 10:39
Gary R. Wheeler13-May-08 10:39 
GeneralRe: Is this a horror? Pin
Gary R. Wheeler15-May-08 11:27
Gary R. Wheeler15-May-08 11:27 
GeneralRe: Is this a horror? Pin
Jörgen Sigvardsson16-May-08 1:13
Jörgen Sigvardsson16-May-08 1:13 
GeneralRe: Is this a horror? Pin
Gary R. Wheeler16-May-08 11:12
Gary R. Wheeler16-May-08 11:12 
GeneralC# confessions - Oh man I would be embarassed - if it wasn't so funny. Pin
GuyThiebaut8-May-08 3:59
professionalGuyThiebaut8-May-08 3:59 
GeneralRe: C# confessions - Oh man I would be embarassed - if it wasn't so funny. Pin
CPallini8-May-08 4:44
mveCPallini8-May-08 4:44 
GeneralRe: C# confessions - Oh man I would be embarassed - if it wasn't so funny. Pin
CDP18028-May-08 22:09
CDP18028-May-08 22:09 
GeneralRe: C# confessions - Oh man I would be embarassed - if it wasn't so funny. Pin
GuyThiebaut8-May-08 23:20
professionalGuyThiebaut8-May-08 23:20 

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.