ATLAS Offline Software
Namespaces | Functions
get_unaligned.h File Reference

Read little-endian values through possibly unaligned pointers. More...

#include "CxxUtils/restrict.h"
#include <cstring>
#include <stdint.h>
Include dependency graph for get_unaligned.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 CxxUtils
 

Functions

uint16_t CxxUtils::htole16 (uint16_t x)
 
uint32_t CxxUtils::htole32 (uint32_t x)
 
uint64_t CxxUtils::htole64 (uint64_t x)
 
uint16_t CxxUtils::get_unaligned16 (const uint8_t *ATH_RESTRICT &p)
 Read a 2-byte little-endian value from a possibly unaligned pointer. More...
 
uint32_t CxxUtils::get_unaligned32 (const uint8_t *ATH_RESTRICT &p)
 Read a 4-byte little-endian value from a possibly unaligned pointer. More...
 
uint64_t CxxUtils::get_unaligned64 (const uint8_t *ATH_RESTRICT &p)
 Read a 8-byte little-endian value from a possibly unaligned pointer. More...
 
float CxxUtils::get_unaligned_float (const uint8_t *ATH_RESTRICT &p)
 Read little-endian float value from a possibly unaligned pointer. More...
 
double CxxUtils::get_unaligned_double (const uint8_t *ATH_RESTRICT &p)
 Read little-endian float value from a possibly unaligned pointer. More...
 
template<class T >
CxxUtils::get_unaligned (const uint8_t *ATH_RESTRICT &p)
 Define templated versions of the above functions. More...
 
template<>
uint8_t CxxUtils::get_unaligned< uint8_t > (const uint8_t *ATH_RESTRICT &p)
 
template<>
uint16_t CxxUtils::get_unaligned< uint16_t > (const uint8_t *ATH_RESTRICT &p)
 
template<>
uint32_t CxxUtils::get_unaligned< uint32_t > (const uint8_t *ATH_RESTRICT &p)
 
template<>
uint64_t CxxUtils::get_unaligned< uint64_t > (const uint8_t *ATH_RESTRICT &p)
 
template<>
float CxxUtils::get_unaligned< float > (const uint8_t *ATH_RESTRICT &p)
 
template<>
double CxxUtils::get_unaligned< double > (const uint8_t *ATH_RESTRICT &p)
 
template<>
int8_t CxxUtils::get_unaligned< int8_t > (const uint8_t *ATH_RESTRICT &p)
 
template<>
int16_t CxxUtils::get_unaligned< int16_t > (const uint8_t *ATH_RESTRICT &p)
 
template<>
int32_t CxxUtils::get_unaligned< int32_t > (const uint8_t *ATH_RESTRICT &p)
 
template<>
int64_t CxxUtils::get_unaligned< int64_t > (const uint8_t *ATH_RESTRICT &p)
 

Detailed Description

Read little-endian values through possibly unaligned pointers.

Author
scott snyder snyde.nosp@m.r@bn.nosp@m.l.gov
Date
May, 2019 Doing, eg,
char* p = ...;
int* ip = reinterpret_cast<int*>(p);
int i = *ip++;

is undefined if p isn't aligned to an int boundary. It further will read the value using the host endianness, which is an issue for the common use case of reading persistent data.

The functions here allow reading little-endian data via possibly unaligned pointers regardless of the host byte ordering and without relying on undefined behavior.

Definition in file get_unaligned.h.

python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3