Click here to Skip to main content
15,905,508 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.

 
GeneralThis is just beautiful! Pin
jchigg20001-May-07 5:59
jchigg20001-May-07 5:59 
GeneralRe: This is just beautiful! Pin
CPallini1-May-07 7:46
mveCPallini1-May-07 7:46 
GeneralRe: This is just beautiful! Pin
Pete O'Hanlon1-May-07 10:06
mvePete O'Hanlon1-May-07 10:06 
GeneralRe: This is just beautiful! Pin
The ANZAC2-May-07 0:31
The ANZAC2-May-07 0:31 
GeneralRe: This is just beautiful! Pin
NormDroid3-May-07 1:59
professionalNormDroid3-May-07 1:59 
GeneralI do it really often :) Pin
Kochise4-May-07 4:52
Kochise4-May-07 4:52 
GeneralRe: This is just beautiful! Pin
Sylvester george20-Jun-07 3:15
Sylvester george20-Jun-07 3:15 
GeneralMy introduction to "##" Pin
Todd_s0230-Apr-07 13:36
Todd_s0230-Apr-07 13:36 
I was never one for the intricacies of the C preprocessor. On my latest project, apparently (or rather, unfortunately) someone is.

An .h file has a bunch of definitions (real variable names changed to protect the innocent):

statedefs.h:
<br />
makeState(State1, 0x01)<br />
makeState(State2, 0x02)<br />
makeState(State3, 0x03)<br />


Odd, I think, but ok. Then I go look up "makeState". What the... 3 entries? That's not a good sign.

Instance 1:

<br />
#define makeState(NAME, NUM) ST_##NAME## = ##NUM##,<br />
typedef enum {<br />
#include "statedefs.h"<br />
   ST_LAST } statetype;<br />


Instance 2:
Embedded in the middle of a function(!)

<br />
#undef makestate<br />
#define makeState(NAME, NUM) somevariable++;<br />
   #include "statedefs.h"<br />


Instance 3:
<br />
#define makestate(NAME, NUM) { "ST_"#NAME,0,0},<br />
sometype stateinfo[] =<br />
{<br />
   #include "statedefs.h"<br />
}<br />


There are no external programs being used, no weird autogeneration stuff.. the entire set of code is a replacement for:

<br />
enum<br />
{<br />
   ST_State1 = 1,<br />
   ST_State2 = 2,<br />
   ST_State3 = 3,<br />
<br />
   ST_LAST<br />
}<br />


Most editors I've tried cannot tag it, due to the preprocessor concatenation used ("##" in instance 1). References don't work either. And this is one of the easier to read examples of preprocessor abuse...

I just try and remind myself that code written this way makes it that much easier on my next job interview!
GeneralRe: My introduction to "##" Pin
Michael Dunn30-Apr-07 14:22
sitebuilderMichael Dunn30-Apr-07 14:22 
GeneralRe: My introduction to "##" Pin
Pete O'Hanlon30-Apr-07 22:22
mvePete O'Hanlon30-Apr-07 22:22 
GeneralRe: My introduction to "##" Pin
Marcus J. Smith1-May-07 2:44
professionalMarcus J. Smith1-May-07 2:44 
GeneralRe: My introduction to &quot;##&quot; Pin
Tristan Rhodes1-May-07 5:38
Tristan Rhodes1-May-07 5:38 
GeneralRe: My introduction to &quot;##&quot; Pin
peterchen1-May-07 19:41
peterchen1-May-07 19:41 
GeneralRe: My introduction to &quot;##&quot; Pin
Tristan Rhodes2-May-07 8:59
Tristan Rhodes2-May-07 8:59 
GeneralRe: My introduction to &quot;##&quot; Pin
Pete O'Hanlon2-May-07 1:39
mvePete O'Hanlon2-May-07 1:39 
GeneralRe: My introduction to "##" Pin
peterchen1-May-07 10:45
peterchen1-May-07 10:45 
GeneralRe: My introduction to "##" Pin
PIEBALDconsult1-May-07 15:59
mvePIEBALDconsult1-May-07 15:59 
GeneralRe: My introduction to "##" Pin
peterchen1-May-07 19:31
peterchen1-May-07 19:31 
GeneralRe: My introduction to "##" Pin
PIEBALDconsult2-May-07 3:52
mvePIEBALDconsult2-May-07 3:52 
GeneralRe: My introduction to "##" Pin
Dan Neely2-May-07 3:55
Dan Neely2-May-07 3:55 
GeneralRe: My introduction to &quot;##&quot; Pin
PIEBALDconsult2-May-07 5:23
mvePIEBALDconsult2-May-07 5:23 
JokeRe: My introduction to &quot;##&quot; Pin
Dan Neely2-May-07 7:10
Dan Neely2-May-07 7:10 
GeneralRe: My introduction to &quot;##&quot; Pin
PIEBALDconsult2-May-07 11:11
mvePIEBALDconsult2-May-07 11:11 
GeneralRe: My introduction to "##" Pin
peterchen2-May-07 4:52
peterchen2-May-07 4:52 
GeneralRe: My introduction to "##" Pin
PIEBALDconsult2-May-07 5:33
mvePIEBALDconsult2-May-07 5:33 

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.