Click here to Skip to main content
15,897,181 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: 'Item': member names cannot be the same as their enclosing type Pin
leppie26-Nov-08 9:15
leppie26-Nov-08 9:15 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
WilliamSauron26-Nov-08 9:20
WilliamSauron26-Nov-08 9:20 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
Redwan Albougha26-Nov-08 8:16
Redwan Albougha26-Nov-08 8:16 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
leppie26-Nov-08 2:10
leppie26-Nov-08 2:10 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
Redwan Albougha26-Nov-08 8:21
Redwan Albougha26-Nov-08 8:21 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
Camilo Sanchez26-Nov-08 17:55
Camilo Sanchez26-Nov-08 17:55 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
Redwan Albougha27-Nov-08 2:04
Redwan Albougha27-Nov-08 2:04 
GeneralC++ Gem Pin
Tom Delany11-Nov-08 11:53
Tom Delany11-Nov-08 11:53 
I cam across this C++ gem today in some code that a co-worker wrote. In his defense, the bulk of his programming experience is in OS/390 Assembler.

char *ShowDrive( TAPEDRIVE *DRV, char *out )  {

   int    status;

   char  *msg;

                               status = 0x2D2D;
   if ( DRV->stat & POWERON )  status = 0x4E4F;
   if ( DRV->stat & MOUNTED )  status = 0x544D;
   if ( DRV->stat & STARTED )  status = 0x5453;
   if ( DRV->stat & INTREQD )  status = 0x5249;

  sprintf_s( out, 80,"%2d %4.4s %4.4s %2.2s %6.6s %8.8s %8.8s\n ",
           DRV->slot, DRV->host, DRV->name, &status, DRV->vols, DRV->msg1, DRV->msg2 );

   msg = out + strlen( out );

  sprintf_s( msg, 80,"   Block=%d\n", DRV->blockID );

   return out + strlen( out );
   }


Where do I begin? I especially like the int status variable that he uses in the sprintf_s with a format specifier of "%2.2s". It took me a while to realize that since he used "&status" as the argument, he was forcing sprintf_s to use it as a char pointer, and that the value of the int was two ASCII characters (reversed, because of Little Endianness).

I also like the return of the char pointer that points to the middle of the constructed string. (In his code the return value was ignored.) I'm not wild about the way it plays willy-nilly with the char pointers, etc. Too much horrible crap to even go into it all. My head hurts. D'Oh! | :doh:

WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.

There are 10 kinds of people in the world: People who know binary and people who don't.

GeneralRe: C++ Gem Pin
Rob Grainger11-Nov-08 22:33
Rob Grainger11-Nov-08 22:33 
GeneralRe: C++ Gem Pin
PIEBALDconsult12-Nov-08 5:05
mvePIEBALDconsult12-Nov-08 5:05 
GeneralRe: C++ Gem Pin
supercat912-Nov-08 12:55
supercat912-Nov-08 12:55 
GeneralRe: C++ Gem Pin
Lutosław13-Nov-08 11:47
Lutosław13-Nov-08 11:47 
GeneralRe: C++ Gem Pin
Tom Delany12-Nov-08 16:28
Tom Delany12-Nov-08 16:28 
GeneralRe: C++ Gem Pin
Rob Grainger12-Nov-08 22:06
Rob Grainger12-Nov-08 22:06 
GeneralRe: C++ Gem Pin
Nemanja Trifunovic12-Nov-08 7:46
Nemanja Trifunovic12-Nov-08 7:46 
GeneralRe: C++ Gem Pin
Tom Delany12-Nov-08 16:22
Tom Delany12-Nov-08 16:22 
GeneralRe: C++ Gem Pin
Nemanja Trifunovic13-Nov-08 6:27
Nemanja Trifunovic13-Nov-08 6:27 
GeneralRe: C++ Gem Pin
VentsyV12-Nov-08 9:11
VentsyV12-Nov-08 9:11 
JokeRe: C++ Gem Pin
Emil - Gabriel20-Nov-08 1:03
Emil - Gabriel20-Nov-08 1:03 
GeneralSQL Server trigger code Pin
Bernard Laplace10-Nov-08 1:16
Bernard Laplace10-Nov-08 1:16 
GeneralRe: SQL Server trigger code Pin
Thomas Weller10-Nov-08 4:37
Thomas Weller10-Nov-08 4:37 
GeneralRe: SQL Server trigger code Pin
Bernard Laplace10-Nov-08 5:37
Bernard Laplace10-Nov-08 5:37 
GeneralRe: SQL Server trigger code Pin
Paul Conrad10-Nov-08 17:20
professionalPaul Conrad10-Nov-08 17:20 
GeneralRe: SQL Server trigger code Pin
Thomas Weller10-Nov-08 5:38
Thomas Weller10-Nov-08 5:38 
GeneralWhat will you call this??? Pin
AhsanS7-Nov-08 2:38
AhsanS7-Nov-08 2:38 

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.