Click here to Skip to main content
16,014,309 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: Clever code Pin
Rage31-Jul-07 5:17
professionalRage31-Jul-07 5:17 
GeneralRe: Clever code Pin
Dario Solera31-Jul-07 7:29
Dario Solera31-Jul-07 7:29 
GeneralRe: Clever code Pin
StevenWalsh4-Aug-07 5:33
StevenWalsh4-Aug-07 5:33 
GeneralRe: Clever code Pin
QuiJohn31-Jul-07 5:32
QuiJohn31-Jul-07 5:32 
GeneralRe: Clever code Pin
Dario Solera31-Jul-07 7:26
Dario Solera31-Jul-07 7:26 
GeneralRe: Sorry, .. I forgot to comment ... Pin
Chris Meech31-Jul-07 6:10
Chris Meech31-Jul-07 6:10 
GeneralRe: Clever code Pin
m@u31-Jul-07 6:26
m@u31-Jul-07 6:26 
GeneralRe: Clever code - Here is why it may have been used... [modified] Pin
Pualee31-Jul-07 7:00
Pualee31-Jul-07 7:00 
PosBD = i;
i = PosBD;

The side effects of embedded C code are always amazing. Have you checked the types on these guys or revision history? I am willing to bet one is 16 bit in one file and 32 in another. I'd also wager if that is the case, there is an extern declaration somewhere Smile | :)

It is possible PosBD is overwriting i and the setting i to PosBD fixes it. A later file using the correct size of PosBD will not be affected! A lazy programmer did not check his/her types.

=========== Related experience showing why that might* make sense ============

I once worked on a system with lots of arrays which were global and 16 bit or 32 bit depending on the file they were used in. Needless to say lots of stuff got overwritten and until I realized what the problem was (and fixed it), another engineer did the following temporarily and was baffled:

<br />
extern int32 value[];<br />
extern int32 checks[]<br />
<br />
temp = value[x];<br />
checks[y] = variable;<br />
value[x] = temp;<br />


another file had this from the legacy system(syntax may be a bit off, its been a while)
<br />
int16 value[];<br />
int16 checks[];<br />


This fixed the problem, but he never knew why(found exact line w/ debugger). In reality, the checks array was overwriting the value array whenever the index was greater than half its size!

After I addressed the extern issues and fixed types, other parts of the system randomly started working or breaking (mostly working), depending on how they had been set up. By the end of the project, I was thanked for fixing things not in the spec... even though I had never touched them Smile | :) The client was satisfied.




-- modified at 13:07 Tuesday 31st July, 2007
GeneralRe: Clever code - Here is why it may have been used... Pin
Dario Solera31-Jul-07 7:28
Dario Solera31-Jul-07 7:28 
GeneralRe: Clever code - Here is why it may have been used... Pin
Pualee31-Jul-07 7:30
Pualee31-Jul-07 7:30 
GeneralRe: Clever code Pin
sngbrdb31-Jul-07 7:55
professionalsngbrdb31-Jul-07 7:55 
GeneralRe: Clever code Pin
StevenWalsh4-Aug-07 5:40
StevenWalsh4-Aug-07 5:40 
GeneralJust how many formats can we use to represent the same data? Pin
martin_hughes26-Jul-07 11:58
martin_hughes26-Jul-07 11:58 
GeneralRe: Just how many formats can we use to represent the same data? Pin
Patrick Etc.26-Jul-07 15:30
Patrick Etc.26-Jul-07 15:30 
GeneralRe: Just how many formats can we use to represent the same data? Pin
QuiJohn27-Jul-07 2:24
QuiJohn27-Jul-07 2:24 
GeneralRe: Just how many formats can we use to represent the same data? Pin
Chris Maunder27-Jul-07 3:40
cofounderChris Maunder27-Jul-07 3:40 
GeneralRe: Just how many formats can we use to represent the same data? Pin
codemunkeh27-Jul-07 6:38
codemunkeh27-Jul-07 6:38 
GeneralRe: Just how many formats can we use to represent the same data? Pin
martin_hughes27-Jul-07 7:21
martin_hughes27-Jul-07 7:21 
GeneralRe: Just how many formats can we use to represent the same data? Pin
Ian Shlasko27-Jul-07 11:10
Ian Shlasko27-Jul-07 11:10 
GeneralRe: Just how many formats can we use to represent the same data? Pin
ne0h27-Jul-07 7:31
ne0h27-Jul-07 7:31 
GeneralRe: Just how many formats can we use to represent the same data? Pin
Paul Conrad27-Jul-07 20:12
professionalPaul Conrad27-Jul-07 20:12 
GeneralRe: Just how many formats can we use to represent the same data? Pin
pbraun27-Jul-07 14:14
pbraun27-Jul-07 14:14 
GeneralRe: Just how many formats can we use to represent the same data? Pin
John R. Shaw27-Jul-07 23:30
John R. Shaw27-Jul-07 23:30 
GeneralWell is it SQL or isn't it? Pin
PIEBALDconsult26-Jul-07 10:38
mvePIEBALDconsult26-Jul-07 10:38 
GeneralRe: Well is it SQL or isn't it? Pin
Rob Graham26-Jul-07 11:14
Rob Graham26-Jul-07 11:14 

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.