Skip to content

Commit c11ce21

Browse files
committed
Added mbed_preprocessor.h to collect common cpp definitions
1 parent 98db3ab commit c11ce21

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

platform/mbed_assert.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef MBED_ASSERT_H
2020
#define MBED_ASSERT_H
2121

22+
#include "mbed_preprocessor.h"
23+
2224
#ifdef __cplusplus
2325
extern "C" {
2426
#endif
@@ -50,10 +52,6 @@ do { \
5052
#endif
5153

5254

53-
#define _MBED_CONCAT_(a, b) a##b
54-
#define _MBED_CONCAT(a, b) _MBED_CONCAT_(a, b)
55-
#define _MBED_ASSERTION _MBED_CONCAT(_MBED_ASSERTION_AT_, __LINE__)
56-
5755
/** MBED_STATIC_ASSERT
5856
* Declare compile-time assertions, results in compile-time error if condition is false
5957
*
@@ -90,7 +88,8 @@ do { \
9088
#elif defined(__ICCARM__)
9189
#define MBED_STATIC_ASSERT(expr, msg) static_assert(expr, msg)
9290
#else
93-
#define MBED_STATIC_ASSERT(expr, msg) enum {_MBED_ASSERTION = sizeof(char[(expr) ? 1 : -1])}
91+
#define MBED_STATIC_ASSERT(expr, msg) \
92+
enum {MBED_CONCAT(MBED_ASSERTION_AT_, __LINE__) = sizeof(char[(expr) ? 1 : -1])}
9493
#endif
9594

9695
/** MBED_STRUCT_STATIC_ASSERT

platform/mbed_preprocessor.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/** \addtogroup platform */
2+
/** @{*/
3+
/* mbed Microcontroller Library
4+
* Copyright (c) 2006-2013 ARM Limited
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
#ifndef MBED_PREPROCESSOR_H
19+
#define MBED_PREPROCESSOR_H
20+
21+
22+
/** MBED_CONCAT
23+
* Concatenate tokens together
24+
*
25+
* @note
26+
* Expands tokens before concatenation
27+
*
28+
* @code
29+
* // Creates a unique label based on the line number
30+
* int MBED_CONCAT(UNIQUE_LABEL_, __LINE__) = 1;
31+
* @endcode
32+
*/
33+
#define MBED_CONCAT(a, b) MBED_CONCAT_(a, b)
34+
#define MBED_CONCAT_(a, b) a##b
35+
36+
/** MBED_STRINGIFY
37+
* Converts tokens into strings
38+
*
39+
* @note
40+
* Expands tokens before stringification
41+
*
42+
* @code
43+
* // Creates a string based on the parameters
44+
* const char *c = MBED_STRINGIFY(This is a ridiculous way to create a string)
45+
* @endcode
46+
*/
47+
#define MBED_STRINGIFY(a) MBED_STRINGIFY_(a)
48+
#define MBED_STRINGIFY_(a) #a
49+
50+
51+
#endif
52+
53+
/** @}*/

platform/toolchain.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef MBED_TOOLCHAIN_H
2020
#define MBED_TOOLCHAIN_H
2121

22+
#include "mbed_preprocessor.h"
23+
2224

2325
// Warning for unsupported compilers
2426
#if !defined(__GNUC__) /* GCC */ \
@@ -65,8 +67,7 @@
6567
*/
6668
#ifndef MBED_ALIGN
6769
#if defined(__ICCARM__)
68-
#define _MBED_ALIGN(N) _Pragma(#N)
69-
#define MBED_ALIGN(N) _MBED_ALIGN(data_alignment=N)
70+
#define MBED_ALIGN(N) _Pragma(MBED_STRINGIFY(data_alignment=N))
7071
#else
7172
#define MBED_ALIGN(N) __attribute__((aligned(N)))
7273
#endif

0 commit comments

Comments
 (0)