Skip to content
Snippets Groups Projects
Commit bfd8f297 authored by Daniel Friesel's avatar Daniel Friesel
Browse files

XDR: Add notes about undefined behaviour

parent 2c001e65
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,8 @@ float XDRInput::get_float() ...@@ -41,6 +41,8 @@ float XDRInput::get_float()
uint32_t i; uint32_t i;
float f; float f;
} v; } v;
// Setting one member of a struct and then reading another is undefined
// behaviour, but works as intended in nearly any (embedded) compiler
v.i = get_uint32(); v.i = get_uint32();
return v.f; return v.f;
} }
...@@ -51,6 +53,8 @@ double XDRInput::get_double() ...@@ -51,6 +53,8 @@ double XDRInput::get_double()
uint64_t i; uint64_t i;
double d; double d;
} v; } v;
// Setting one member of a struct and then reading another is undefined
// behaviour, but works as intended in nearly any (embedded) compiler
v.i = get_uint64(); v.i = get_uint64();
return v.d; return v.d;
} }
......
...@@ -74,6 +74,8 @@ XDRStream & XDRStream::operator<<(float number) ...@@ -74,6 +74,8 @@ XDRStream & XDRStream::operator<<(float number)
uint32_t i; uint32_t i;
float f; float f;
} v; } v;
// Setting one member of a struct and then reading another is undefined
// behaviour, but works as intended in nearly any (embedded) compiler
v.f = number; v.f = number;
*this << v.i; *this << v.i;
return *this; return *this;
...@@ -85,6 +87,8 @@ XDRStream & XDRStream::operator<<(double number) ...@@ -85,6 +87,8 @@ XDRStream & XDRStream::operator<<(double number)
uint64_t i; uint64_t i;
double d; double d;
} v; } v;
// Setting one member of a struct and then reading another is undefined
// behaviour, but works as intended in nearly any (embedded) compiler
v.d = number; v.d = number;
*this << v.i; *this << v.i;
return *this; return *this;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment