FastLED 3.9.15
Loading...
Searching...
No Matches
cstddef.h
Go to the documentation of this file.
1#pragma once
2
4// FastLED Standard Definition Types (stddef.h equivalents)
5//
6// Provides size_t, ptrdiff_t, max_align_t, and offsetof macro.
8
9namespace fl {
10
11// FastLED equivalent of std::nullptr_t
12typedef decltype(nullptr) nullptr_t;
13
14// FastLED equivalent of std::size_t and std::ptrdiff_t
15typedef __SIZE_TYPE__ size_t;
16
17#ifdef __PTRDIFF_TYPE__
18typedef __PTRDIFF_TYPE__ ptrdiff_t;
19#else
20// Fallback for compilers that don't define __PTRDIFF_TYPE__ (like older AVR-GCC)
21typedef long ptrdiff_t;
22#endif
23
24// FastLED equivalent of std::max_align_t
25// Use union approach (like standard library implementations) for fast compilation
26// Template-based selection to handle platforms where long double == double
27namespace detail {
28 // Union variant with long double (for platforms with distinct long double like x86/x64)
29 typedef union {
30 long long ll;
31 long double ld;
32 void* p;
34
35 // Union variant without long double (for ARM/AVR where long double == double)
36 typedef union {
37 long long ll;
38 double d;
39 void* p;
41}
42
43// Template selector - automatically chooses correct variant at compile time
44template <bool UseLD>
48
49template <>
53
54// Select appropriate union based on whether long double is distinct from double
55typedef typename max_align_selector<(sizeof(long double) > sizeof(double))>::type max_align_t;
56
57} // namespace fl
58
59// Declare size_t and ptrdiff_t in global namespace for third-party C++ code
60// (avoid max_align_t and nullptr_t which conflict with system headers)
63
64
65// FastLED equivalent of offsetof macro (stddef.h)
66// Computes byte offset of a member within a struct/class at compile time
67// Uses compiler builtin to avoid including <stddef.h>
68// Note: This is C++ only and depends on __cplusplus guard above
69#define FL_OFFSETOF(type, member) __builtin_offsetof(type, member)
fl::size_t size_t
Definition cstddef.h:61
fl::ptrdiff_t ptrdiff_t
Definition cstddef.h:62
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_traits.h:48
max_align_selector<(sizeof(longdouble)>sizeof(double))>::type max_align_t
Definition cstddef.h:55
decltype(nullptr) nullptr_t
Definition cstddef.h:12
fl::size size_t
Definition s16x16x4.h:223
fl::ptrdiff ptrdiff_t
Definition s16x16x4.h:226
Base definition for an LED controller.
Definition crgb.hpp:179
detail::max_align_with_ld type
Definition cstddef.h:46
detail::max_align_without_ld type
Definition cstddef.h:51