The whole purpose of UNDEFINED is the ability to get to the special case of zero that UNDEFINED is without using a kludge such as ([])[0]. In general you would on the other hand test for such a value using zero_type().
However you can't use if(variable == UNDEFINED) { ... } since that will match if variable is either 0 or UNDEFINED.
On a related note, I think it would be nice if uninitialized variables ended up being UNDEFINED rather than 0. I.e:
int i; [... do something ...] if(zero_type(i)) { blah }
/ David Hedbor
Previous text:
2003-01-22 07:03: Subject: Re: zero_type() & UNDEFINED (bug?)
On Wed, Jan 22, 2003 at 03:40:00AM +0100, David Hedbor @ Pike developers forum wrote:
zero_type(0);
(2) Result: 0
zero_type(UNDEFINED);
(3) Result: 1
But:
typeof(UNDEFINED);
(27) Result: zero
typeof(0);
(28) Result: zero
sprintf("%t", 0);
(29) Result: "int"
sprintf("%t", UNDEFINED);
(30) Result: "int"
A bit unlogical... :)
Regards, /Al
/ Brevbäraren