C++ Logo

liaison

Advanced search

[wg14/wg21 liaison] indeterminate value

From: Uecker, Martin <Martin.Uecker_at_[hidden]>
Date: Wed, 17 Feb 2021 13:46:23 +0000


Hi all,


in C++ "indeterminate values" exist also for expressions
and not just for objects (C does not really have
indeterminate values although the current terminology
implies this).


It seems that operations involving "indeterminate values"
are UB, except for some specific exceptions involving
unsigned characters. For example it seems you can
initialize a variable of unsigned character
type with an indeterminate value and this is then
not UB. (N4860 6.7.4)

I am a bit puzzled what the purpose is of these rules.
Allowing some operations on uninitialized
variables could make sense to not make programs UB
which do propagate them accidentally in some code path
but then never use the value. But then why is this
limited to unsigned characters?

Accessing bytes in memory which are possibly uninitialized
is a useful feature and this works safely in C when
using character types (which do not have trap representations).
If the byte is uninitialized the value is unspecified
but consistent. In C++ this does not seem to work as
indeterminate values read then cause UB later.

So I wonder whether someone could shed some light on this?


Best,
Martin




Received on 2021-02-17 07:46:31