MetaChrome
MetaChrome

Reputation: 3220

Is there a contextually standard value for NaN for int?

  1. In a lot of runtimes, the int type has a default value initialized.
  2. Most languages do not by default provide a null holder for basic types.
  3. A holder reference would cause an additional usually unnecessary member lookup.

Considering this, has a value emerged among programmers to specify null/uninitialized in acceptable contexts?

Presumably, a value just inside the range of the int type would be appropriate.

Upvotes: 0

Views: 38

Answers (1)

Chris Devereux
Chris Devereux

Reputation: 5473

Two examples I can think of that are sometimes used:

  • For an unsigned value, using a signed type and returning -1 to indicate error.
  • MAX_INT or equivalent.

Upvotes: 1

Related Questions