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

 
AnswerRe: zero int? Pin
CDP180221-Nov-11 23:30
CDP180221-Nov-11 23:30 
GeneralRe: zero int? Pin
Nagy Vilmos21-Nov-11 23:50
professionalNagy Vilmos21-Nov-11 23:50 
GeneralRe: zero int? Pin
CDP180221-Nov-11 23:52
CDP180221-Nov-11 23:52 
GeneralRe: zero int? Pin
KP Lee2-Dec-11 23:51
KP Lee2-Dec-11 23:51 
GeneralRe: zero int? Pin
harold aptroot3-Dec-11 2:11
harold aptroot3-Dec-11 2:11 
GeneralRe: zero int? Pin
KP Lee3-Dec-11 3:02
KP Lee3-Dec-11 3:02 
GeneralRe: zero int? Pin
harold aptroot3-Dec-11 3:27
harold aptroot3-Dec-11 3:27 
GeneralRe: zero int? Pin
KP Lee3-Dec-11 10:21
KP Lee3-Dec-11 10:21 
There is a difference between local and declared variables. int IS set to zero here:
// set these variables in the declaration section
bool isEmpty = false;
int[] num;
bool isEmpty2;
int num2;
private void SetEndElement(bool strt, bool outer, bool vert)
{
    // have these in a routine, it will compile without error
    if (num == null) isEmpty = true;
    // I expected a runtime error here, but it runs, isEmpty2 is false, num2 is 0
    if (num2 == null) isEmpty2 = true;


The following produces 2 warnings and 2 errors and won't compile
Warning 1 The variable 'isEmpty' is assigned but its value is never used ... (stats on where the error is)
...
Error 3 Use of unassigned local variable 'num' ...

private void SetEndElement(bool strt, bool outer, bool vert)
{
    bool isEmpty = false;
    int[] num;
    bool isEmpty2;
    int num2;
    if (num == null) isEmpty = true;
    if (num2 == null) isEmpty2 = true;

So we're both wrong. Smile | :)
harold aptroot wrote:
warning that it's always false.

GeneralRe: zero int? Pin
harold aptroot3-Dec-11 10:42
harold aptroot3-Dec-11 10:42 
GeneralRe: zero int? Pin
KP Lee3-Dec-11 11:06
KP Lee3-Dec-11 11:06 
GeneralRe: zero int? Pin
harold aptroot3-Dec-11 11:19
harold aptroot3-Dec-11 11:19 
GeneralRe: zero int? Pin
Chris Berger22-Nov-11 8:46
Chris Berger22-Nov-11 8:46 
GeneralRe: zero int? Pin
greldak23-Nov-11 2:59
greldak23-Nov-11 2:59 
GeneralRe: zero int? Pin
CDP180223-Nov-11 3:03
CDP180223-Nov-11 3:03 
GeneralRe: zero int? Pin
KP Lee3-Dec-11 0:40
KP Lee3-Dec-11 0:40 
GeneralRe: zero int? Pin
harold aptroot23-Nov-11 4:12
harold aptroot23-Nov-11 4:12 
GeneralRe: zero int? Pin
jsc4223-Nov-11 7:44
professionaljsc4223-Nov-11 7:44 
JokeRe: zero int? Pin
harold aptroot23-Nov-11 8:01
harold aptroot23-Nov-11 8:01 
JokeRe: zero int? Pin
Stefan_Lang12-Dec-11 6:18
Stefan_Lang12-Dec-11 6:18 
GeneralRe: zero int? Pin
BobJanova23-Nov-11 5:14
BobJanova23-Nov-11 5:14 
GeneralRe: zero int? Pin
CDP180223-Nov-11 5:17
CDP180223-Nov-11 5:17 
GeneralRe: zero int? Pin
AspDotNetDev23-Nov-11 6:45
protectorAspDotNetDev23-Nov-11 6:45 
GeneralRe: zero int? Pin
harold aptroot23-Nov-11 7:24
harold aptroot23-Nov-11 7:24 
GeneralRe: zero int? Pin
AspDotNetDev23-Nov-11 11:08
protectorAspDotNetDev23-Nov-11 11:08 
GeneralRe: zero int? Pin
KP Lee3-Dec-11 1:51
KP Lee3-Dec-11 1:51 

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.