CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Null vs 0

  1. #1
    Guest

    Null vs 0

    My application uses dialog boxes that capture and display numbers. However, these numbers are not required. So, my question is - Can I initialize my ints, doubles, and floats to some kind of a NULL value that IS NOT a 0 (number zero)?


  2. #2
    Guest

    Re: Null vs 0

    Strictly, no, you can't. A weak approach is to pick some value and use it as a "NULL". For example, if a the acceptable range of input is non-negative numbers, you could use -1. For floats, a really large negative number might be appropriate.

    If you need a stronger method and need to pass these things around, you could create a structure which includes a initialized flag along with an element to hold the value (unions might make this easier). This is the approach used in the Variant type used in VB and OLE.

    If you are dealing with edit boxes, you can map them to strings. An empty string is NULL, and anything else you could convert to a number.





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured