Is owner > 0x0
a good way to test if an address owner
was set in Solidity?
I am not sure if this could break something in the future and if there are better ways to see if the address was set. What is the best solution?
1 Answer
Though this works, I personally think it is a good idea to have both operand types equal on boolean operations , as you mentioned for future compatibility.
Instead of using > operator use equality == or != , as in case of address the greater operator may not make sense.
Instead of using 0x0 use address(0) or address(0x0), as it would make much more of type of address.
So your code would look like
owner==address(0);// check if the address is not set
Just my 2 cents
-
thanks, what is a Neo Noir Dev? Has it to do with Film Noir? Commented Jul 2, 2016 at 20:14
-
11
-
1it merely typecasts uint 0 to an address (0x000...) Commented Jun 18, 2018 at 14:01
-
-
@JohnAllen it is not documented per se in the Solidity documentation, but both contracts Voting and BlindAuction mention them : solidity.readthedocs.io/en/v0.5.11/…– CJ42Commented Aug 15, 2019 at 9:38