diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2019-06-28 07:46:40 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2019-06-28 07:46:40 +0200 |
commit | bfd8f297e6af00841d93e807e3e33e5a6e6e226e (patch) | |
tree | 127aaa12df65b8ae26be3b57f11b3fee8bcf34a3 | |
parent | 2c001e655002ee713457342197a7005217cd16b4 (diff) |
XDR: Add notes about undefined behaviour
-rw-r--r-- | src/os/object/xdrinput.cc | 4 | ||||
-rw-r--r-- | src/os/object/xdrstream.cc | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/os/object/xdrinput.cc b/src/os/object/xdrinput.cc index 612244e..e722fdd 100644 --- a/src/os/object/xdrinput.cc +++ b/src/os/object/xdrinput.cc @@ -41,6 +41,8 @@ float XDRInput::get_float() uint32_t i; float f; } 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(); return v.f; } @@ -51,6 +53,8 @@ double XDRInput::get_double() uint64_t i; double d; } 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(); return v.d; } diff --git a/src/os/object/xdrstream.cc b/src/os/object/xdrstream.cc index ad708be..f0c9365 100644 --- a/src/os/object/xdrstream.cc +++ b/src/os/object/xdrstream.cc @@ -74,6 +74,8 @@ XDRStream & XDRStream::operator<<(float number) uint32_t i; float f; } 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; *this << v.i; return *this; @@ -85,6 +87,8 @@ XDRStream & XDRStream::operator<<(double number) uint64_t i; double d; } 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; *this << v.i; return *this; |