Loading...
Searching...
No Matches
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
9#pragma once
10
38
39#include <stdint.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
46typedef struct __attribute__((packed)) {
47 uint16_t val;
49
51typedef struct __attribute__((packed)) {
52 uint32_t val;
54
56typedef struct __attribute__((packed)) {
57 uint64_t val;
59
67static inline uint16_t unaligned_get_u16(const void *ptr)
68{
69 const uint16_una_t *tmp = (const uint16_una_t *)ptr;
70 return tmp->val;
71}
72
80static inline uint32_t unaligned_get_u32(const void *ptr)
81{
82 const uint32_una_t *tmp = (const uint32_una_t *)ptr;
83 return tmp->val;
84}
85
93static inline uint64_t unaligned_get_u64(const void *ptr)
94{
95 const uint64_una_t *tmp = (const uint64_una_t *)ptr;
96 return tmp->val;
97}
98
99#ifdef __cplusplus
100}
101#endif
102
static uint16_t unaligned_get_u16(const void *ptr)
Get uint16_t from possibly unaligned pointer.
Definition unaligned.h:67
static uint64_t unaligned_get_u64(const void *ptr)
Get uint64_t from possibly unaligned pointer.
Definition unaligned.h:93
static uint32_t unaligned_get_u32(const void *ptr)
Get uint32_t from possibly unaligned pointer.
Definition unaligned.h:80
Unaligned access helper struct (uint16_t version)
Definition unaligned.h:46
uint16_t val
value
Definition unaligned.h:47
Unaligned access helper struct (uint32_t version)
Definition unaligned.h:51
uint32_t val
value
Definition unaligned.h:52
Unaligned access helper struct (uint64_t version)
Definition unaligned.h:56
uint64_t val
value
Definition unaligned.h:57