Click here to Skip to main content
15,905,325 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: 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 "##" Pin
Tristan Rhodes1-May-07 5:38
Tristan Rhodes1-May-07 5:38 
GeneralRe: My introduction to "##" Pin
peterchen1-May-07 19:41
peterchen1-May-07 19:41 
GeneralRe: My introduction to "##" Pin
Tristan Rhodes2-May-07 8:59
Tristan Rhodes2-May-07 8:59 
GeneralRe: My introduction to "##" 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 
somestateinfo gives you literal strings for the names, so it's a replacement for:

enum
{
  ST_State1 = 1,
  ST_State2 = 2,
  ST_State3 = 3,

  ST_LAST
}

sometype stateinfo[] =
{
  { "ST_State1", 0, 0 },
  { "ST_State2", 0, 0 },
  { "ST_State2", 0, 0 },
}


If he'd used, say, #define makestate(NAME, NUM) { "ST_"#NAME,NUM,0},
you could derive a name-value mapping for enums. It could even remove a prefix from the enum constant.

The "inside a function" counts the values actually defined, which would be better derived from sizeof(stateinfo)/sizeof(stateinfo[0])

Not that I ever endorse such conding practices Roll eyes | :rolleyes:
But it's a not-to-unusual way around lack of reflection in C / C++.



We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
My first real C# project | Linkify!|FoldWithUs! | sighist

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 "##" Pin
PIEBALDconsult2-May-07 5:23
mvePIEBALDconsult2-May-07 5:23 
JokeRe: My introduction to "##" Pin
Dan Neely2-May-07 7:10
Dan Neely2-May-07 7:10 
GeneralRe: My introduction to "##" 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 
GeneralRe: My introduction to "##" Pin
Anton Afanasyev2-May-07 13:40
Anton Afanasyev2-May-07 13:40 
GeneralRe: My introduction to "##" Pin
PIEBALDconsult2-May-07 15:12
mvePIEBALDconsult2-May-07 15:12 
GeneralRe: My introduction to "##" Pin
peterchen13-Dec-10 2:39
peterchen13-Dec-10 2:39 
GeneralRe: My introduction to "##" Pin
PIEBALDconsult2-May-07 20:10
mvePIEBALDconsult2-May-07 20:10 
GeneralRe: My introduction to "##" Pin
peterchen2-May-07 20:46
peterchen2-May-07 20:46 
GeneralRe: My introduction to "##" Pin
KarstenK2-May-07 23:36
mveKarstenK2-May-07 23:36 
GeneralAlien Assembly Search Pin
Brady Kelly28-Apr-07 2:54
Brady Kelly28-Apr-07 2:54 
GeneralRe: Alien Assembly Search Pin
John R. Shaw28-Apr-07 12:42
John R. Shaw28-Apr-07 12:42 

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.