unaligned.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Kaspar Schleiser <kaspar@schleiser.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
37 #ifndef UNALIGNED_H
38 #define UNALIGNED_H
39 
40 #include <stdint.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
47 typedef struct __attribute__((packed)) {
48  uint16_t val;
49 } uint16_una_t;
50 
58 static inline uint16_t unaligned_get_u16(const void *ptr)
59 {
60  const uint16_una_t *tmp = ptr;
61  return tmp->val;
62 }
63 
64 #ifdef __cplusplus
65 }
66 #endif
67 
69 #endif /* UNALIGNED_H */
uint16_t val
value
Definition: unaligned.h:48
static uint16_t unaligned_get_u16(const void *ptr)
Get uint16_t from possibly unaligned pointer.
Definition: unaligned.h:58
Unaligned access helper struct (uint16_t version)
Definition: unaligned.h:47