Skip to content

Commit d962ce3

Browse files
author
mikee47
committed
Fix problem defining arrays in class declarations
For example, this code produces `__fstr__myIntArray not defined` error: ``` struct MyClass { DEFINE_FSTR_ARRAY_LOCAL(myIntArray, int, 1, 2, 3, 4, 5) }; ``` The same issue applies to maps and vectors.
1 parent 8f91c37 commit d962ce3

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/include/FlashString/Array.hpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,20 @@
6363
* @param ... List of ElementType items
6464
*/
6565
#define DEFINE_FSTR_ARRAY_DATA(name, ElementType, ...) \
66+
DEFINE_FSTR_ARRAY_DATA_SIZED(name, ElementType, FSTR_VA_NARGS(ElementType, __VA_ARGS__), __VA_ARGS__)
67+
68+
/**
69+
* @brief Define an Array data structure, specifying the number of elements
70+
* @param name Name of data structure
71+
* @param ElementType
72+
* @param size Number of elements
73+
* @param ... List of ElementType items
74+
*/
75+
#define DEFINE_FSTR_ARRAY_DATA_SIZED(name, ElementType, size, ...) \
6676
FSTR_CONSTEXPR const struct { \
6777
FSTR::ObjectBase object; \
68-
ElementType data[FSTR_VA_NARGS(ElementType, __VA_ARGS__)]; \
69-
} FSTR_PACKED FSTR_ALIGNED name PROGMEM = {{sizeof(name.data)}, {__VA_ARGS__}}; \
78+
ElementType data[size]; \
79+
} FSTR_PACKED FSTR_ALIGNED name PROGMEM = {{sizeof(ElementType) * size}, {__VA_ARGS__}}; \
7080
FSTR_CHECK_STRUCT(name);
7181

7282
/**

src/include/FlashString/Map.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
FSTR_CONSTEXPR const struct { \
104104
FSTR::ObjectBase object; \
105105
FSTR::MapPair<KeyType, ContentType> data[size]; \
106-
} FSTR_PACKED FSTR_ALIGNED name PROGMEM = {{sizeof(name.data)}, {__VA_ARGS__}}; \
106+
} FSTR_PACKED FSTR_ALIGNED name PROGMEM = {{sizeof(FSTR::MapPair<KeyType, ContentType>) * size}, {__VA_ARGS__}}; \
107107
FSTR_CHECK_STRUCT(name);
108108

109109
namespace FSTR

src/include/FlashString/Vector.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
FSTR_CONSTEXPR const struct { \
9898
FSTR::ObjectBase object; \
9999
const ObjectType* data[size]; \
100-
} name PROGMEM = {{sizeof(name.data)}, {__VA_ARGS__}}; \
100+
} name PROGMEM = {{sizeof(ObjectType*) * size}, {__VA_ARGS__}}; \
101101
FSTR_CHECK_STRUCT(name);
102102

103103
namespace FSTR

0 commit comments

Comments
 (0)