Browse Source

Add static assert to catch errors in COPY(a,b)

Scott Lahteine 6 years ago
parent
commit
ca73b2f465
1 changed files with 4 additions and 1 deletions
  1. 4
    1
      Marlin/src/core/macros.h

+ 4
- 1
Marlin/src/core/macros.h View File

152
 #define DECIMAL_SIGNED(a) (DECIMAL(a) || (a) == '-' || (a) == '+')
152
 #define DECIMAL_SIGNED(a) (DECIMAL(a) || (a) == '-' || (a) == '+')
153
 #define COUNT(a) (sizeof(a)/sizeof(*a))
153
 #define COUNT(a) (sizeof(a)/sizeof(*a))
154
 #define ZERO(a) memset(a,0,sizeof(a))
154
 #define ZERO(a) memset(a,0,sizeof(a))
155
-#define COPY(a,b) memcpy(a,b,MIN(sizeof(a),sizeof(b)))
155
+#define COPY(a,b) do{ \
156
+    static_assert(sizeof(a[0]) == sizeof(b[0]), "COPY: '" STRINGIFY(a) "' and '" STRINGIFY(b) "' types (sizes) don't match!"); \
157
+    memcpy(&a[0],&b[0],MIN(sizeof(a),sizeof(b))); \
158
+  }while(0)
156
 
159
 
157
 // Macros for initializing arrays
160
 // Macros for initializing arrays
158
 #define ARRAY_6(v1, v2, v3, v4, v5, v6, ...) { v1, v2, v3, v4, v5, v6 }
161
 #define ARRAY_6(v1, v2, v3, v4, v5, v6, ...) { v1, v2, v3, v4, v5, v6 }

Loading…
Cancel
Save