How can I check if an Contract variable is undefined
in Solidity?
According to this
Memory-stored objects as local variables are correctly zero-initialised: Members of structs and elements of fixed-size arrays are recursively initialised, dynamic arrays are set to zero length. delete x assigns a new zero-initialised value to x.
There is no such undefined variable. All objects are zero-initalised.
By some Solidity coding conventions you add a boolean 'valid' element to any struct to indicate it is undefined (false is the initialized value).
Sometimes I see fields having zero reserved to mean undefined - e.g. treat 0 as an undefined address. You could also do that for a string, but string is often externally input so you have to make sure someone didn't send you a zero string.
I would advise using a field where zero is naturally meaningful like a separate bool or an existing address element in a struct.
-
1
-