<s>
In	O
computer	B-General_Concept
programming	I-General_Concept
,	O
undefined	B-Language
behavior	I-Language
(	O
UB	O
)	O
is	O
the	O
result	O
of	O
executing	O
a	O
program	O
whose	O
behavior	O
is	O
prescribed	O
to	O
be	O
unpredictable	O
,	O
in	O
the	O
language	O
specification	O
to	O
which	O
the	O
computer	B-Application
code	I-Application
adheres	O
.	O
</s>
<s>
This	O
is	O
different	O
from	O
unspecified	B-Language
behavior	I-Language
,	O
for	O
which	O
the	O
language	O
specification	O
does	O
not	O
prescribe	O
a	O
result	O
,	O
and	O
implementation-defined	O
behavior	O
that	O
defers	O
to	O
the	O
documentation	O
of	O
another	O
component	O
of	O
the	O
platform	B-Device
(	O
such	O
as	O
the	O
ABI	B-Operating_System
or	O
the	O
translator	B-Application
documentation	O
)	O
.	O
</s>
<s>
In	O
the	O
C	B-Language
community	I-Language
,	O
undefined	B-Language
behavior	I-Language
may	O
be	O
humorously	O
referred	O
to	O
as	O
"	O
nasal	B-Language
demons	I-Language
"	O
,	O
after	O
a	O
comp.std.c	B-Architecture
post	O
that	O
explained	O
undefined	B-Language
behavior	I-Language
as	O
allowing	O
the	O
compiler	B-Language
to	O
do	O
anything	O
it	O
chooses	O
,	O
even	O
"	O
to	O
make	O
demons	O
fly	O
out	O
of	O
your	O
nose	O
"	O
.	O
</s>
<s>
Some	O
programming	O
languages	O
allow	O
a	O
program	O
to	O
operate	O
differently	O
or	O
even	O
have	O
a	O
different	O
control	O
flow	O
than	O
the	O
source	O
code	O
,	O
as	O
long	O
as	O
it	O
exhibits	O
the	O
same	O
user-visible	O
side	O
effects	O
,	O
if	O
undefined	B-Language
behavior	I-Language
never	O
happens	O
during	O
program	O
execution	O
.	O
</s>
<s>
Undefined	B-Language
behavior	I-Language
is	O
the	O
name	O
of	O
a	O
list	O
of	O
conditions	O
that	O
the	O
program	O
must	O
not	O
meet	O
.	O
</s>
<s>
In	O
the	O
early	O
versions	O
of	O
C	B-Language
,	O
undefined	B-Language
behavior	I-Language
's	O
primary	O
advantage	O
was	O
the	O
production	O
of	O
performant	O
compilers	B-Language
for	O
a	O
wide	O
variety	O
of	O
machines	O
:	O
a	O
specific	O
construct	O
could	O
be	O
mapped	O
to	O
a	O
machine-specific	O
feature	O
,	O
and	O
the	O
compiler	B-Language
did	O
not	O
have	O
to	O
generate	O
additional	O
code	O
for	O
the	O
runtime	B-Device
to	O
adapt	O
the	O
side	O
effects	O
to	O
match	O
semantics	O
imposed	O
by	O
the	O
language	O
.	O
</s>
<s>
The	O
program	O
source	O
code	O
was	O
written	O
with	O
prior	O
knowledge	O
of	O
the	O
specific	O
compiler	B-Language
and	O
of	O
the	O
platforms	B-Device
that	O
it	O
would	O
support	O
.	O
</s>
<s>
However	O
,	O
progressive	O
standardization	O
of	O
the	O
platforms	B-Device
has	O
made	O
this	O
less	O
of	O
an	O
advantage	O
,	O
especially	O
in	O
newer	O
versions	O
of	O
C	B-Language
.	O
Now	O
,	O
the	O
cases	O
for	O
undefined	B-Language
behavior	I-Language
typically	O
represent	O
unambiguous	O
bugs	B-Error_Name
in	O
the	O
code	O
,	O
for	O
example	O
indexing	O
an	O
array	B-Data_Structure
outside	O
of	O
its	O
bounds	O
.	O
</s>
<s>
By	O
definition	O
,	O
the	O
runtime	B-Device
can	O
assume	O
that	O
undefined	B-Language
behavior	I-Language
never	O
happens	O
;	O
therefore	O
,	O
some	O
invalid	O
conditions	O
do	O
not	O
need	O
to	O
be	O
checked	O
against	O
.	O
</s>
<s>
For	O
a	O
compiler	B-Language
,	O
this	O
also	O
means	O
that	O
various	O
program	B-Application
transformations	I-Application
become	O
valid	O
,	O
or	O
their	O
proofs	O
of	O
correctness	O
are	O
simplified	O
;	O
this	O
allows	O
for	O
various	O
kinds	O
of	O
optimizations	O
whose	O
correctness	O
depend	O
on	O
the	O
assumption	O
that	O
the	O
program	O
state	O
never	O
meets	O
any	O
such	O
condition	O
.	O
</s>
<s>
The	O
compiler	B-Language
can	O
also	O
remove	O
explicit	O
checks	O
that	O
may	O
have	O
been	O
in	O
the	O
source	O
code	O
,	O
without	O
notifying	O
the	O
programmer	O
;	O
for	O
example	O
,	O
detecting	O
undefined	B-Language
behavior	I-Language
by	O
testing	O
whether	O
it	O
happened	O
is	O
not	O
guaranteed	O
to	O
work	O
,	O
by	O
definition	O
.	O
</s>
<s>
This	O
makes	O
it	O
hard	O
or	O
impossible	O
to	O
program	O
a	O
portable	B-Application
fail-safe	O
option	O
(	O
non-portable	O
solutions	O
are	O
possible	O
for	O
some	O
constructs	O
)	O
.	O
</s>
<s>
Current	O
compiler	B-Language
development	O
usually	O
evaluates	O
and	O
compares	O
compiler	B-Language
performance	O
with	O
benchmarks	O
designed	O
around	O
micro-optimizations	O
,	O
even	O
on	O
platforms	B-Device
that	O
are	O
mostly	O
used	O
on	O
the	O
general-purpose	O
desktop	O
and	O
laptop	O
market	O
(	O
such	O
as	O
amd64	O
)	O
.	O
</s>
<s>
Therefore	O
,	O
undefined	B-Language
behavior	I-Language
provides	O
ample	O
room	O
for	O
compiler	B-Language
performance	O
improvement	O
,	O
as	O
the	O
source	O
code	O
for	O
a	O
specific	O
source	O
code	O
statement	O
is	O
allowed	O
to	O
be	O
mapped	O
to	O
anything	O
at	O
runtime	B-Device
.	O
</s>
<s>
For	O
C	B-Language
and	O
C++	O
,	O
the	O
compiler	B-Language
is	O
allowed	O
to	O
give	O
a	O
compile-time	O
diagnostic	O
in	O
these	O
cases	O
,	O
but	O
is	O
not	O
required	O
to	O
:	O
the	O
implementation	O
will	O
be	O
considered	O
correct	O
whatever	O
it	O
does	O
in	O
such	O
cases	O
,	O
analogous	O
to	O
don't-care	O
terms	O
in	O
digital	O
logic	O
.	O
</s>
<s>
It	O
is	O
the	O
responsibility	O
of	O
the	O
programmer	O
to	O
write	O
code	O
that	O
never	O
invokes	O
undefined	B-Language
behavior	I-Language
,	O
although	O
compiler	B-Language
implementations	O
are	O
allowed	O
to	O
issue	O
diagnostics	O
when	O
this	O
happens	O
.	O
</s>
<s>
Compilers	B-Language
nowadays	O
have	O
flags	O
that	O
enable	O
such	O
diagnostics	O
,	O
for	O
example	O
,	O
-fsanitize	O
=	O
undefined	O
enables	O
the	O
"	O
undefined	B-Language
behavior	I-Language
sanitizer	O
"	O
(	O
UBSan	O
)	O
in	O
gcc	B-Application
4.9	O
and	O
in	O
clang	B-Application
.	O
</s>
<s>
Under	O
some	O
circumstances	O
there	O
can	O
be	O
specific	O
restrictions	O
on	O
undefined	B-Language
behavior	I-Language
.	O
</s>
<s>
For	O
example	O
,	O
the	O
instruction	B-General_Concept
set	I-General_Concept
specifications	O
of	O
a	O
CPU	B-General_Concept
might	O
leave	O
the	O
behavior	O
of	O
some	O
forms	O
of	O
an	O
instruction	O
undefined	O
,	O
but	O
if	O
the	O
CPU	B-General_Concept
supports	O
memory	B-General_Concept
protection	I-General_Concept
then	O
the	O
specification	O
will	O
probably	O
include	O
a	O
blanket	O
rule	O
stating	O
that	O
no	O
user-accessible	O
instruction	O
may	O
cause	O
a	O
hole	O
in	O
the	O
operating	B-General_Concept
system	I-General_Concept
's	O
security	O
;	O
so	O
an	O
actual	O
CPU	B-General_Concept
would	O
be	O
permitted	O
to	O
corrupt	O
user	O
registers	O
in	O
response	O
to	O
such	O
an	O
instruction	O
,	O
but	O
would	O
not	O
be	O
allowed	O
to	O
,	O
for	O
example	O
,	O
switch	O
into	O
supervisor	O
mode	O
.	O
</s>
<s>
The	O
runtime	B-Device
platform	B-Device
can	O
also	O
provide	O
some	O
restrictions	O
or	O
guarantees	O
on	O
undefined	B-Language
behavior	I-Language
,	O
if	O
the	O
toolchain	B-General_Concept
or	O
the	O
runtime	B-Device
explicitly	O
document	O
that	O
specific	O
constructs	O
found	O
in	O
the	O
source	O
code	O
are	O
mapped	O
to	O
specific	O
well-defined	O
mechanisms	O
available	O
at	O
runtime	B-Device
.	O
</s>
<s>
For	O
example	O
,	O
an	O
interpreter	B-Application
may	O
document	O
a	O
particular	O
behavior	O
for	O
some	O
operations	O
that	O
are	O
undefined	O
in	O
the	O
language	O
specification	O
,	O
while	O
other	O
interpreters	B-Application
or	O
compilers	B-Language
for	O
the	O
same	O
language	O
may	O
not	O
.	O
</s>
<s>
A	O
compiler	B-Language
produces	O
executable	B-Application
code	I-Application
for	O
a	O
specific	O
ABI	B-Operating_System
,	O
filling	O
the	O
semantic	O
gap	O
in	O
ways	O
that	O
depend	O
on	O
the	O
compiler	B-Language
version	O
:	O
the	O
documentation	O
for	O
that	O
compiler	B-Language
version	O
and	O
the	O
ABI	B-Operating_System
specification	O
can	O
provide	O
restrictions	O
on	O
undefined	B-Language
behavior	I-Language
.	O
</s>
<s>
Relying	O
on	O
these	O
implementation	O
details	O
makes	O
the	O
software	O
non-portable	O
,	O
but	O
portability	O
may	O
not	O
be	O
a	O
concern	O
if	O
the	O
software	O
is	O
not	O
supposed	O
to	O
be	O
used	O
outside	O
of	O
a	O
specific	O
runtime	B-Device
.	O
</s>
<s>
Undefined	B-Language
behavior	I-Language
can	O
result	O
in	O
a	O
program	O
crash	O
or	O
even	O
in	O
failures	O
that	O
are	O
harder	O
to	O
detect	O
and	O
make	O
the	O
program	O
look	O
like	O
it	O
is	O
working	O
normally	O
,	O
such	O
as	O
silent	O
loss	O
of	O
data	O
and	O
production	O
of	O
incorrect	O
results	O
.	O
</s>
<s>
Documenting	O
an	O
operation	O
as	O
undefined	B-Language
behavior	I-Language
allows	O
compilers	B-Language
to	O
assume	O
that	O
this	O
operation	O
will	O
never	O
happen	O
in	O
a	O
conforming	O
program	O
.	O
</s>
<s>
This	O
gives	O
the	O
compiler	B-Language
more	O
information	O
about	O
the	O
code	O
and	O
this	O
information	O
can	O
lead	O
to	O
more	O
optimization	O
opportunities	O
.	O
</s>
<s>
An	O
example	O
for	O
the	O
C	B-Language
language	I-Language
:	O
</s>
<s>
The	O
value	O
of	O
x	O
cannot	O
be	O
negative	O
and	O
,	O
given	O
that	O
signed	O
integer	B-Error_Name
overflow	I-Error_Name
is	O
undefined	B-Language
behavior	I-Language
in	O
C	B-Language
,	O
the	O
compiler	B-Language
can	O
assume	O
that	O
value	O
<	O
2147483600	O
will	O
always	O
be	O
false	O
.	O
</s>
<s>
Thus	O
the	O
if	O
statement	O
,	O
including	O
the	O
call	O
to	O
the	O
function	O
bar	O
,	O
can	O
be	O
ignored	O
by	O
the	O
compiler	B-Language
since	O
the	O
test	O
expression	O
in	O
the	O
if	O
has	O
no	O
side	O
effects	O
and	O
its	O
condition	O
will	O
never	O
be	O
satisfied	O
.	O
</s>
<s>
Had	O
the	O
compiler	B-Language
been	O
forced	O
to	O
assume	O
that	O
signed	O
integer	B-Error_Name
overflow	I-Error_Name
has	O
wraparound	O
behavior	O
,	O
then	O
the	O
transformation	O
above	O
would	O
not	O
have	O
been	O
legal	O
.	O
</s>
<s>
The	O
compiler	B-Language
is	O
free	O
to	O
optimize	O
away	O
the	O
while-loop	O
here	O
by	O
applying	O
value	O
range	O
analysis	O
:	O
by	O
inspecting	O
foo( )	O
,	O
it	O
knows	O
that	O
the	O
initial	O
value	O
pointed	O
to	O
by	O
ptrx	O
cannot	O
possibly	O
exceed	O
47	O
(	O
as	O
any	O
more	O
would	O
trigger	O
undefined	B-Language
behavior	I-Language
in	O
foo( )	O
)	O
;	O
therefore	O
,	O
the	O
initial	O
check	O
of	O
*	O
ptrx	O
>	O
60	O
will	O
always	O
be	O
false	O
in	O
a	O
conforming	O
program	O
.	O
</s>
<s>
Going	O
further	O
,	O
since	O
the	O
result	O
z	O
is	O
now	O
never	O
used	O
and	O
foo( )	O
has	O
no	O
side	O
effects	O
,	O
the	O
compiler	B-Language
can	O
optimize	O
run_tasks( )	O
to	O
be	O
an	O
empty	O
function	O
that	O
returns	O
immediately	O
.	O
</s>
<s>
The	O
disappearance	O
of	O
the	O
while-loop	O
may	O
be	O
especially	O
surprising	O
if	O
foo( )	O
is	O
defined	O
in	O
a	O
separately	O
compiled	B-Language
object	O
file	O
.	O
</s>
<s>
Another	O
benefit	O
from	O
allowing	O
signed	O
integer	B-Error_Name
overflow	I-Error_Name
to	O
be	O
undefined	O
is	O
that	O
it	O
makes	O
it	O
possible	O
to	O
store	O
and	O
manipulate	O
a	O
variable	O
's	O
value	O
in	O
a	O
processor	B-General_Concept
register	I-General_Concept
that	O
is	O
larger	O
than	O
the	O
size	O
of	O
the	O
variable	O
in	O
the	O
source	O
code	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
the	O
type	O
of	O
a	O
variable	O
as	O
specified	O
in	O
the	O
source	O
code	O
is	O
narrower	O
than	O
the	O
native	O
register	B-General_Concept
width	I-General_Concept
(	O
such	O
as	O
int	O
on	O
a	O
64-bit	B-Device
machine	O
,	O
a	O
common	O
scenario	O
)	O
,	O
then	O
the	O
compiler	B-Language
can	O
safely	O
use	O
a	O
signed	O
64-bit	B-Device
integer	O
for	O
the	O
variable	O
in	O
the	O
machine	B-Language
code	I-Language
it	O
produces	O
,	O
without	O
changing	O
the	O
defined	O
behavior	O
of	O
the	O
code	O
.	O
</s>
<s>
If	O
a	O
program	O
depended	O
on	O
the	O
behavior	O
of	O
a	O
32-bit	O
integer	B-Error_Name
overflow	I-Error_Name
,	O
then	O
a	O
compiler	B-Language
would	O
have	O
to	O
insert	O
additional	O
logic	O
when	O
compiling	B-Language
for	O
a	O
64-bit	B-Device
machine	O
,	O
because	O
the	O
overflow	O
behavior	O
of	O
most	O
machine	B-Language
instructions	I-Language
depends	O
on	O
the	O
register	B-General_Concept
width	I-General_Concept
.	O
</s>
<s>
Undefined	B-Language
behavior	I-Language
also	O
allows	O
more	O
compile-time	O
checks	O
by	O
both	O
compilers	B-Language
and	O
static	O
program	O
analysis	O
.	O
</s>
<s>
C	B-Language
and	O
C++	O
standards	O
have	O
several	O
forms	O
of	O
undefined	B-Language
behavior	I-Language
throughout	O
,	O
which	O
offer	O
increased	O
liberty	O
in	O
compiler	B-Language
implementations	O
and	O
compile-time	O
checks	O
at	O
the	O
expense	O
of	O
undefined	O
run-time	O
behavior	O
if	O
present	O
.	O
</s>
<s>
In	O
particular	O
,	O
the	O
ISO	O
standard	O
for	O
C	B-Language
has	O
an	O
appendix	O
listing	O
common	O
sources	O
of	O
undefined	B-Language
behavior	I-Language
.	O
</s>
<s>
Moreover	O
,	O
compilers	B-Language
are	O
not	O
required	O
to	O
diagnose	O
code	O
that	O
relies	O
on	O
undefined	B-Language
behavior	I-Language
.	O
</s>
<s>
Hence	O
,	O
it	O
is	O
common	O
for	O
programmers	O
,	O
even	O
experienced	O
ones	O
,	O
to	O
rely	O
on	O
undefined	B-Language
behavior	I-Language
either	O
by	O
mistake	O
,	O
or	O
simply	O
because	O
they	O
are	O
not	O
well-versed	O
in	O
the	O
rules	O
of	O
the	O
language	O
that	O
can	O
span	O
hundreds	O
of	O
pages	O
.	O
</s>
<s>
This	O
can	O
result	O
in	O
bugs	B-Error_Name
that	O
are	O
exposed	O
when	O
a	O
different	O
compiler	B-Language
,	O
or	O
different	O
settings	O
,	O
are	O
used	O
.	O
</s>
<s>
Testing	O
or	O
fuzzing	O
with	O
dynamic	O
undefined	B-Language
behavior	I-Language
checks	O
enabled	O
,	O
e.g.	O
,	O
the	O
Clang	B-Application
sanitizers	O
,	O
can	O
help	O
to	O
catch	O
undefined	B-Language
behavior	I-Language
not	O
diagnosed	O
by	O
the	O
compiler	B-Language
or	O
static	O
analyzers	O
.	O
</s>
<s>
Undefined	B-Language
behavior	I-Language
can	O
lead	O
to	O
security	O
vulnerabilities	O
in	O
software	O
.	O
</s>
<s>
For	O
example	O
,	O
buffer	B-General_Concept
overflows	I-General_Concept
and	O
other	O
security	O
vulnerabilities	O
in	O
the	O
major	O
web	B-Application
browsers	I-Application
are	O
due	O
to	O
undefined	B-Language
behavior	I-Language
.	O
</s>
<s>
The	O
Year	B-Application
2038	I-Application
problem	I-Application
is	O
another	O
example	O
due	O
to	O
signed	O
integer	B-Error_Name
overflow	I-Error_Name
.	O
</s>
<s>
When	O
GCC	B-Application
's	O
developers	O
changed	O
their	O
compiler	B-Language
in	O
2008	O
such	O
that	O
it	O
omitted	O
certain	O
overflow	O
checks	O
that	O
relied	O
on	O
undefined	B-Language
behavior	I-Language
,	O
CERT	O
issued	O
a	O
warning	O
against	O
the	O
newer	O
versions	O
of	O
the	O
compiler	B-Language
.	O
</s>
<s>
Linux	O
Weekly	O
News	O
pointed	O
out	O
that	O
the	O
same	O
behavior	O
was	O
observed	O
in	O
PathScale	B-Language
C	I-Language
,	O
Microsoft	B-Application
Visual	I-Application
C++	I-Application
2005	I-Application
and	O
several	O
other	O
compilers	B-Language
;	O
the	O
warning	O
was	O
later	O
amended	O
to	O
warn	O
about	O
various	O
compilers	B-Language
.	O
</s>
<s>
The	O
major	O
forms	O
of	O
undefined	B-Language
behavior	I-Language
in	O
C	B-Language
can	O
be	O
broadly	O
classified	O
as	O
:	O
spatial	O
memory	O
safety	O
violations	O
,	O
temporal	O
memory	O
safety	O
violations	O
,	O
integer	B-Error_Name
overflow	I-Error_Name
,	O
strict	O
aliasing	O
violations	O
,	O
alignment	O
violations	O
,	O
unsequenced	O
modifications	O
,	O
data	O
races	O
,	O
and	O
loops	O
that	O
neither	O
perform	O
I/O	O
nor	O
terminate	O
.	O
</s>
<s>
In	O
C	B-Language
the	O
use	O
of	O
any	O
automatic	B-General_Concept
variable	I-General_Concept
before	O
it	O
has	O
been	O
initialized	O
yields	O
undefined	B-Language
behavior	I-Language
,	O
as	O
does	O
integer	O
division	B-Algorithm
by	I-Algorithm
zero	I-Algorithm
,	O
signed	O
integer	B-Error_Name
overflow	I-Error_Name
,	O
indexing	O
an	O
array	B-Data_Structure
outside	O
of	O
its	O
defined	O
bounds	O
(	O
see	O
buffer	B-General_Concept
overflow	I-General_Concept
)	O
,	O
or	O
null	O
pointer	O
dereferencing	O
.	O
</s>
<s>
In	O
general	O
,	O
any	O
instance	O
of	O
undefined	B-Language
behavior	I-Language
leaves	O
the	O
abstract	O
execution	O
machine	O
in	O
an	O
unknown	O
state	O
,	O
and	O
causes	O
the	O
behavior	O
of	O
the	O
entire	O
program	O
to	O
be	O
undefined	O
.	O
</s>
<s>
Attempting	O
to	O
modify	O
a	O
string	B-Language
literal	I-Language
causes	O
undefined	B-Language
behavior	I-Language
:	O
</s>
<s>
Integer	O
division	B-Algorithm
by	I-Algorithm
zero	I-Algorithm
results	O
in	O
undefined	B-Language
behavior	I-Language
:	O
</s>
<s>
Certain	O
pointer	O
operations	O
may	O
result	O
in	O
undefined	B-Language
behavior	I-Language
:	O
</s>
<s>
In	O
C	B-Language
and	O
C++	O
,	O
the	O
relational	O
comparison	O
of	O
pointers	O
to	O
objects	O
(	O
for	O
less-than	O
or	O
greater-than	O
comparison	O
)	O
is	O
only	O
strictly	O
defined	O
if	O
the	O
pointers	O
point	O
to	O
members	O
of	O
the	O
same	O
object	O
,	O
or	O
elements	O
of	O
the	O
same	O
array	B-Data_Structure
.	O
</s>
<s>
Reaching	O
the	O
end	O
of	O
a	O
value-returning	O
function	O
(	O
other	O
than	O
main( )	O
)	O
without	O
a	O
return	O
statement	O
results	O
in	O
undefined	B-Language
behavior	I-Language
if	O
the	O
value	O
of	O
the	O
function	O
call	O
is	O
used	O
by	O
the	O
caller	O
:	O
</s>
<s>
Modifying	O
an	O
object	O
between	O
two	O
sequence	B-Application
points	I-Application
more	O
than	O
once	O
produces	O
undefined	B-Language
behavior	I-Language
.	O
</s>
<s>
There	O
are	O
considerable	O
changes	O
in	O
what	O
causes	O
undefined	B-Language
behavior	I-Language
in	O
relation	O
to	O
sequence	B-Application
points	I-Application
as	O
of	O
C++11	O
.	O
</s>
<s>
Modern	O
compilers	B-Language
can	O
emit	O
warnings	O
when	O
they	O
encounter	O
multiple	O
unsequenced	O
modifications	O
to	O
the	O
same	O
object	O
.	O
</s>
<s>
The	O
following	O
example	O
will	O
cause	O
undefined	B-Language
behavior	I-Language
in	O
both	O
C	B-Language
and	O
C++	O
.	O
</s>
<s>
When	O
modifying	O
an	O
object	O
between	O
two	O
sequence	B-Application
points	I-Application
,	O
reading	O
the	O
value	O
of	O
the	O
object	O
for	O
any	O
other	O
purpose	O
than	O
determining	O
the	O
value	O
to	O
be	O
stored	O
is	O
also	O
undefined	B-Language
behavior	I-Language
.	O
</s>
<s>
In	O
C/C	O
++	O
bitwise	O
shifting	O
a	O
value	O
by	O
a	O
number	O
of	O
bits	O
which	O
is	O
either	O
a	O
negative	O
number	O
or	O
is	O
greater	O
than	O
or	O
equal	O
to	O
the	O
total	O
number	O
of	O
bits	O
in	O
this	O
value	O
results	O
in	O
undefined	B-Language
behavior	I-Language
.	O
</s>
<s>
The	O
safest	O
way	O
(	O
regardless	O
of	O
compiler	B-Language
vendor	O
)	O
is	O
to	O
always	O
keep	O
the	O
number	O
of	O
bits	O
to	O
shift	O
(	O
the	O
right	O
operand	O
of	O
the	O
<< and >> bitwise operators )  within the range: <0, sizeof(value ) *CHAR_BIT - 1>	O
(	O
where	O
value	O
is	O
the	O
left	O
operand	O
)	O
.	O
</s>
<s>
While	O
undefined	B-Language
behavior	I-Language
is	O
never	O
present	O
in	O
safe	O
Rust	B-Application
,	O
it	O
is	O
possible	O
to	O
invoke	O
undefined	B-Language
behavior	I-Language
in	O
unsafe	O
Rust	B-Application
in	O
many	O
ways	O
.	O
</s>
<s>
For	O
example	O
,	O
creating	O
an	O
invalid	O
reference	O
(	O
a	O
reference	O
which	O
does	O
not	O
refer	O
to	O
a	O
valid	O
value	O
)	O
invokes	O
immediate	O
undefined	B-Language
behavior	I-Language
:	O
</s>
<s>
Note	O
that	O
it	O
is	O
not	O
necessary	O
to	O
use	O
the	O
reference	O
;	O
undefined	B-Language
behavior	I-Language
is	O
invoked	O
merely	O
from	O
the	O
creation	O
of	O
such	O
a	O
reference	O
.	O
</s>
