I found this in c99 standard
3.17.2
1 indeterminate value
either an unspecified value or a trap representation
This above statement is not clear to me. Can anyone explain what is this and what are its pros and cons?
Some example will be highly appreciated.
One of the most common indeterminate examples is zero over zero. Dividing any number by zero is undefined, it could be any value.
An undefined expression involving some operation between two quantities is called a determinate form if it evaluates to a single number value or infinity. An undefined expression involving some operation between two quantities is called an indeterminate form if it does not evaluate to a single number value or infinity.
Unsourced material may be challenged and removed. In mathematics, particularly in formal algebra, an indeterminate is a symbol that is treated as a variable, does not stand for anything else except itself. It may be used as a placeholder in objects such as polynomials and formal power series.
When calculus books state that 00 is an indeterminate form, they mean that there are functions f(x) and g(x) such that f(x) approaches 0 and g(x) approaches 0 as x approaches 0, and that one must evaluate the limit of [f(x)]g(x) as x approaches 0.
The differentiation of the two (indeterminate values and trap representations) is fundamental. In one case you have no known value. In the other you have a known-invalid value.
Simplest example of an indeterminate value I can muster:
int a;
int b = a;
There is no concept of determinate 'value' associated with a
. It has something (as it is occupying memory) but the "what" it has is not defined, thus indeterminate. Overall, the concept is as simple as it sounds: Unless it has been decided what something is, it cannot be used in any evaluation (think r-value if it helps) with deterministic results.
The actual value depends on the language, compiler, and memory management policies. For instance, in most implementations of C, an uninitialized scope variable or the memory pointed to by the pointer returned by a call to malloc will contain whatever value happened to be stored at that address previously. On the other hand, most scripting languages will initialize variables to some default value (0, "", etc).
Regarding Trap Representation, it is essentially any value that is outside the restricted domain of the allowable values pertaining to the underlying formal definition. A hopefully non-confusing example follows. :
enum FooBar { foo=0, bar=1 };
enum FooBar fb = (enum FooBar)2;
In general it is any bit pattern that falls within the space allowed by the underlying storage representation (in enums that is likely an int
) but is NOT considered a valid "value" for the restricted domain of its formal definition. An outstanding description on trap representations and their roots can be found at this answer. The above is just a representative of what a very simple known-invalid representation may appear as. In reality it is practiced in hardware for detection of values that trigger invalid-state. I think of them as "panic" values. Again, the above code is solely idealistic in demonstrating the concept of a "value" this is not "valid", but is, in fact, known.
Unless otherwise specified, static objects contain zero or null pointer values upon program startup. Automatically and dynamically allocated objects are initialized only if an initial value is explicitly specified; otherwise they initially have indeterminate values (typically, whatever bit pattern happens to be present in the storage, which might not even represent a valid value for that type).
Reference : WikiPedia
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With