• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

The story of 0, 1 and null

Status
Not open for further replies.
Contributions from SirNikolas and Volchachka were there aswell.
I've decided to compare NULL with integers. Here are the results:

JASS:
// null<=0   -   true
// null==0   -   true
// null>=0   -   true
// null>0    -   false
// null<0    -   false
// null!=0   -   false

// null<=1   -   true
// null==1   -   false
// null>=1   -   false
// null>1    -   false
// null<1    -   true
// null!=1   -   true

The code for testing:
JASS:
function TestByteCodingBug takes nothing returns nothing
    local string boolDesc = "false"
    if null <= 0 then
        set boolDesc = "true"
    endif
    call BJDebugMsg("null<=0   -   "+boolDesc)
    
    set boolDesc = "false"
    if null == 0 then
        set boolDesc = "true"
    endif
    call BJDebugMsg("null==0   -   "+boolDesc)
    
    set boolDesc = "false"
    if null >= 0 then
        set boolDesc = "true"
    endif
    call BJDebugMsg("null>=0   -   "+boolDesc)
    
    set boolDesc = "false"
    if null > 0 then
        set boolDesc = "true"
    endif
    call BJDebugMsg("null>0   -   "+boolDesc)
    
    set boolDesc = "false"
    if null < 0 then
        set boolDesc = "true"
    endif
    call BJDebugMsg("null<0   -   "+boolDesc)
    
    set boolDesc = "false"
    if null != 0 then
        set boolDesc = "true"
    endif
    call BJDebugMsg("null!=0   -   "+boolDesc)
    
    call BJDebugMsg("============================")
    
    set boolDesc = "false"
    if null <= 1 then
        set boolDesc = "true"
    endif
    call BJDebugMsg("null<=1   -   "+boolDesc)
    
    set boolDesc = "false"
    if null == 1 then
        set boolDesc = "true"
    endif
    call BJDebugMsg("null==1   -   "+boolDesc)
    
    set boolDesc = "false"
    if null >= 1 then
        set boolDesc = "true"
    endif
    call BJDebugMsg("null>=1   -   "+boolDesc)
    
    set boolDesc = "false"
    if null > 1 then
        set boolDesc = "true"
    endif
    call BJDebugMsg("null>1   -   "+boolDesc)
    
    set boolDesc = "false"
    if null < 1 then
        set boolDesc = "true"
    endif
    call BJDebugMsg("null<1   -   "+boolDesc)
    
    set boolDesc = "false"
    if null != 1 then
        set boolDesc = "true"
    endif
    call BJDebugMsg("null!=1   -   "+boolDesc)
endfunction

What can it be?
 
not really... you can only convert/compare values if the target type has an equivalent for it...

null to 0 conversion is simply a value to integer value conversion... since integer type has an equivalent for null, the conversion/comparison proceeds

and since void doesn't have an equivalent for null (I don't think it even has any values inside it), then the conversion cannot proceed...

as for the functions take and returns part, you put types there not values... which is probably why it won't compile (since again, null is not a type)...

JASS:
//doing this
function X takes null returns null

//is like doing this
function Y takes "RAWR" returns "RAWR"

//or this

function Z takes 0 returns 0

//All of them won't compile

This is my guess...
 
Last edited:
I believe null is for non integer related stuffs.
As null = 0, then null will have 0 value as integer (and real?), but others like handle can't accept 0 as value (because handle aren't numbers), thus null is the valid replacement. That's what I can think for null = 0.
anyway, this topic really interest me. Better subscribe before lost track.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
yeah... one of the earliest things I learned in programming is that null is equivalent to 0...

null = nothing
0 = nothing

by one of the mathematical laws, if a = b and b = c then a = c

so null = nothing = 0
null is not always equivalent to 0, it depends on the language

Mathematical laws dont apply to programming, especially when it comes to pointers and stuff. "=" in the mathematical understanding is an equivalence relation (the property you refered to is known as "transitivity"), however that relation is defined for real numbers which are very different from variables that are used in programming in the way that variables have both a value and a type.

And being able to compare different datatypes doesnt mean they are fully compatible in all operations. Example: You can compare (<,>,=,!=) integers and reals, but you cannot use reals as arguments for a function that expects integers.
 
Status
Not open for further replies.
Top