mbed_preprocessor.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /** \addtogroup platform */
  2. /** @{*/
  3. /**
  4. * \defgroup platform_preprocessor preprocessor macros
  5. * @{
  6. */
  7. /* mbed Microcontroller Library
  8. * Copyright (c) 2006-2013 ARM Limited
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. #ifndef MBED_PREPROCESSOR_H
  23. #define MBED_PREPROCESSOR_H
  24. /** MBED_CONCAT
  25. * Concatenate tokens together
  26. *
  27. * @note
  28. * Expands tokens before concatenation
  29. *
  30. * @code
  31. * // Creates a unique label based on the line number
  32. * int MBED_CONCAT(UNIQUE_LABEL_, __LINE__) = 1;
  33. * @endcode
  34. */
  35. #define MBED_CONCAT(a, b) MBED_CONCAT_(a, b)
  36. #define MBED_CONCAT_(a, b) a##b
  37. /** MBED_STRINGIFY
  38. * Converts tokens into strings
  39. *
  40. * @note
  41. * Expands tokens before stringification
  42. *
  43. * @code
  44. * // Creates a string based on the parameters
  45. * const char *c = MBED_STRINGIFY(This is a ridiculous way to create a string)
  46. * @endcode
  47. */
  48. #define MBED_STRINGIFY(a) MBED_STRINGIFY_(a)
  49. #define MBED_STRINGIFY_(a) #a
  50. /** MBED_STRLEN
  51. * Reports string token length
  52. *
  53. * @note
  54. * Expands tokens before calculating length
  55. *
  56. * @code
  57. * // Get string length
  58. * const int len = MBED_STRLEN("Get the length")
  59. * @endcode
  60. */
  61. #define MBED_STRLEN(a) MBED_STRLEN_(a)
  62. #define MBED_STRLEN_(a) (sizeof(a) - 1)
  63. /** MBED_COUNT_VA_ARGS(...)
  64. * Reports number of tokens passed
  65. *
  66. * @note
  67. * Token limit is 16
  68. *
  69. * @code
  70. * // Get number of arguments
  71. * const int count = MBED_COUNT_VA_ARGS("Address 0x%x, Data[0] = %d Data[1] = %d", 0x20001234, 10, 20)
  72. * @endcode
  73. */
  74. #define MBED_COUNT_VA_ARGS(...) GET_NTH_ARG_(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
  75. #define GET_NTH_ARG_(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, N, ...) N
  76. #endif
  77. /** @}*/
  78. /** @}*/