PageRenderTime 38ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/external/mbed/error.h

https://github.com/thecylax/gcc4mbed
C Header | 72 lines | 11 code | 4 blank | 57 comment | 0 complexity | 81bd2c5f1cbaaa44da54b56f94c729bc MD5 | raw file
Possible License(s): LGPL-3.0
  1. /* mbed Microcontroller Library
  2. * Copyright (c) 2006-2013 ARM Limited
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. #ifndef MBED_ERROR_H
  23. #define MBED_ERROR_H
  24. /** To generate a fatal compile-time error, you can use the pre-processor #error directive.
  25. *
  26. * @code
  27. * #error "That shouldn't have happened!"
  28. * @endcode
  29. *
  30. * If the compiler evaluates this line, it will report the error and stop the compile.
  31. *
  32. * For example, you could use this to check some user-defined compile-time variables:
  33. *
  34. * @code
  35. * #define NUM_PORTS 7
  36. * #if (NUM_PORTS > 4)
  37. * #error "NUM_PORTS must be less than 4"
  38. * #endif
  39. * @endcode
  40. *
  41. * Reporting Run-Time Errors:
  42. * To generate a fatal run-time error, you can use the mbed error() function.
  43. *
  44. * @code
  45. * error("That shouldn't have happened!");
  46. * @endcode
  47. *
  48. * If the mbed running the program executes this function, it will print the
  49. * message via the USB serial port, and then die with the blue lights of death!
  50. *
  51. * The message can use printf-style formatting, so you can report variables in the
  52. * message too. For example, you could use this to check a run-time condition:
  53. *
  54. * @code
  55. * if(x >= 5) {
  56. * error("expected x to be less than 5, but got %d", x);
  57. * }
  58. * #endcode
  59. */
  60. #include <stdlib.h>
  61. #include "device.h"
  62. #ifdef DEVICE_STDIO_MESSAGES
  63. #include <stdio.h>
  64. #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1))
  65. #else
  66. #define error(...) (exit(1))
  67. #endif
  68. #endif