Click here to Skip to main content
15,891,423 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: Classical unitialized C pointer Pin
Albert Holguin23-Jan-12 4:52
professionalAlbert Holguin23-Jan-12 4:52 
JokeRe: Classical unitialized C pointer Pin
cpkilekofp27-Jan-12 6:35
cpkilekofp27-Jan-12 6:35 
GeneralRe: Classical unitialized C pointer Pin
ii_noname_ii24-Jan-12 3:42
ii_noname_ii24-Jan-12 3:42 
GeneralRe: Classical unitialized C pointer Pin
cpkilekofp27-Jan-12 6:48
cpkilekofp27-Jan-12 6:48 
GeneralRe: Classical unitialized C pointer Pin
Stefan_Lang25-Jan-12 4:44
Stefan_Lang25-Jan-12 4:44 
GeneralRe: Classical unitialized C pointer Pin
Jochen Arndt25-Jan-12 5:51
professionalJochen Arndt25-Jan-12 5:51 
GeneralRe: Classical unitialized C pointer Pin
cpkilekofp27-Jan-12 6:51
cpkilekofp27-Jan-12 6:51 
GeneralRe: Classical unitialized C pointer Pin
Stefan_Lang29-Jan-12 22:16
Stefan_Lang29-Jan-12 22:16 
Yes, uninitialized pointers can be nasty, especially since they normally will be 0 when you look at the problem in debug builds and thus fail to reproduce the issue. But that alone (i. e. a bug that happens only in release) is enough of on an indication for me to look at initialization first.

Fortunately modern runtimes will no longer accept pointers that do not point into at least the data segment, or aren't aligned properly, so you're normally able to find the culprit very fast.

I, too, intialize every variable, to the point of assigning at least 0 (or nullptr, now), even when the actual initialization happens only two lines below. The point being, that 'two lines below' will likely not remain 'only two lines' in the long run.

I also sometimes use an intialization function for a class, so I can call it in each constructor. While it's more efficient to use initializers in each constructor, it's way too easy to forget one when introducing additional members later. I wonder why initializers for member variables are not allowed... Confused | :confused:
GeneralRe: Classical unitialized C pointer Pin
MarvinMartian28-Jan-12 11:50
MarvinMartian28-Jan-12 11:50 
GeneralRe: Classical unitialized C pointer Pin
YvesDaoust29-Jan-12 21:01
YvesDaoust29-Jan-12 21:01 
GeneralRe: Classical unitialized C pointer Pin
Jochen Arndt29-Jan-12 21:32
professionalJochen Arndt29-Jan-12 21:32 
GeneralRe: Classical unitialized C pointer Pin
YvesDaoust29-Jan-12 23:02
YvesDaoust29-Jan-12 23:02 
GeneralRe: Classical unitialized C pointer Pin
Jochen Arndt29-Jan-12 23:10
professionalJochen Arndt29-Jan-12 23:10 
GeneralRe: Classical unitialized C pointer Pin
YvesDaoust29-Jan-12 23:27
YvesDaoust29-Jan-12 23:27 
GeneralRe: Classical unitialized C pointer Pin
Jochen Arndt29-Jan-12 23:52
professionalJochen Arndt29-Jan-12 23:52 
GeneralRe: Classical unitialized C pointer Pin
YvesDaoust30-Jan-12 0:10
YvesDaoust30-Jan-12 0:10 
GeneralRe: Classical unitialized C pointer Pin
Jochen Arndt30-Jan-12 0:24
professionalJochen Arndt30-Jan-12 0:24 
GeneralRe: Classical unitialized C pointer Pin
YvesDaoust30-Jan-12 0:37
YvesDaoust30-Jan-12 0:37 
GeneralRe: Classical unitialized C pointer Pin
Jochen Arndt30-Jan-12 1:12
professionalJochen Arndt30-Jan-12 1:12 
GeneralCode Optimize Pin
Rajesh Anuhya16-Jan-12 3:06
professionalRajesh Anuhya16-Jan-12 3:06 
GeneralRe: Code Optimize PinPopular
BobJanova16-Jan-12 3:40
BobJanova16-Jan-12 3:40 
GeneralRe: Code Optimize Pin
Florin Jurcovici16-Jan-12 22:02
Florin Jurcovici16-Jan-12 22:02 
GeneralRe: Code Optimize Pin
BobJanova16-Jan-12 22:46
BobJanova16-Jan-12 22:46 
GeneralRe: Code Optimize Pin
James Lonero17-Jan-12 17:14
James Lonero17-Jan-12 17:14 
GeneralRe: Code Optimize Pin
cpkilekofp27-Jan-12 7:02
cpkilekofp27-Jan-12 7:02 

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.