The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

To null or not to null? by Khaar2009-01-29 02:19:43
  By the time is is used, it must be initialized by huitzilopochtli 2009-01-29 05:11:34
Or, in other words, there must be no code path that allows the variable to be referenced while not yet initialized.

That leaves the problem of what value to initialize it to. I'm assuming you have a situation where, depending on other parameters, your value either gets assigned some specific value, or is left unassigned.
When the time comes to check the value, you have no way of distinguishing between the two states.

If you're using flotaing-point variable, they have a few special values (NaN, NegativeInfinity and PositiveInfinity) which might be useful. In case of integer types, you might define a certain value (MinValue, MaxValue, 0, -1, or whatever) as invalid and use that.
[ Reply ]

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)