[Ethereum] Ways to see if address is empty

contract-developmentsolidity

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?

Best 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

Related Topic