nothing changed

Fork of mbed by gokmen ascioglu

Committer:
Jing_Qiu
Date:
Tue Mar 03 00:55:57 2015 +0000
Revision:
1:27d81db81dd7
Parent:
0:a8fa94490a0a
revise

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gokmenascioglu 0:a8fa94490a0a 1 /* mbed Microcontroller Library - error
gokmenascioglu 0:a8fa94490a0a 2 * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
gokmenascioglu 0:a8fa94490a0a 3 */
gokmenascioglu 0:a8fa94490a0a 4
gokmenascioglu 0:a8fa94490a0a 5 #ifndef MBED_ERROR_H
gokmenascioglu 0:a8fa94490a0a 6 #define MBED_ERROR_H
gokmenascioglu 0:a8fa94490a0a 7
gokmenascioglu 0:a8fa94490a0a 8 /* Reporting Compile-Time Errors:
gokmenascioglu 0:a8fa94490a0a 9 * To generate a fatal compile-time error, you can use the pre-processor #error directive.
gokmenascioglu 0:a8fa94490a0a 10 *
gokmenascioglu 0:a8fa94490a0a 11 * > #error "That shouldn't have happened!"
gokmenascioglu 0:a8fa94490a0a 12 *
gokmenascioglu 0:a8fa94490a0a 13 * If the compiler evaluates this line, it will report the error and stop the compile.
gokmenascioglu 0:a8fa94490a0a 14 *
gokmenascioglu 0:a8fa94490a0a 15 * For example, you could use this to check some user-defined compile-time variables:
gokmenascioglu 0:a8fa94490a0a 16 *
gokmenascioglu 0:a8fa94490a0a 17 * > #define NUM_PORTS 7
gokmenascioglu 0:a8fa94490a0a 18 * > #if (NUM_PORTS > 4)
gokmenascioglu 0:a8fa94490a0a 19 * > #error "NUM_PORTS must be less than 4"
gokmenascioglu 0:a8fa94490a0a 20 * > #endif
gokmenascioglu 0:a8fa94490a0a 21 *
gokmenascioglu 0:a8fa94490a0a 22 * Reporting Run-Time Errors:
gokmenascioglu 0:a8fa94490a0a 23 * To generate a fatal run-time error, you can use the mbed error() function.
gokmenascioglu 0:a8fa94490a0a 24 *
gokmenascioglu 0:a8fa94490a0a 25 * > error("That shouldn't have happened!");
gokmenascioglu 0:a8fa94490a0a 26 *
gokmenascioglu 0:a8fa94490a0a 27 * If the mbed running the program executes this function, it will print the
gokmenascioglu 0:a8fa94490a0a 28 * message via the USB serial port, and then die with the blue lights of death!
gokmenascioglu 0:a8fa94490a0a 29 *
gokmenascioglu 0:a8fa94490a0a 30 * The message can use printf-style formatting, so you can report variables in the
gokmenascioglu 0:a8fa94490a0a 31 * message too. For example, you could use this to check a run-time condition:
gokmenascioglu 0:a8fa94490a0a 32 *
gokmenascioglu 0:a8fa94490a0a 33 * > if(x >= 5) {
gokmenascioglu 0:a8fa94490a0a 34 * > error("expected x to be less than 5, but got %d", x);
gokmenascioglu 0:a8fa94490a0a 35 * > }
gokmenascioglu 0:a8fa94490a0a 36 */
gokmenascioglu 0:a8fa94490a0a 37
gokmenascioglu 0:a8fa94490a0a 38 #if 0 // for documentation only
gokmenascioglu 0:a8fa94490a0a 39 /* Function: error
gokmenascioglu 0:a8fa94490a0a 40 * Report a fatal runtime error
gokmenascioglu 0:a8fa94490a0a 41 *
gokmenascioglu 0:a8fa94490a0a 42 * Outputs the specified error message to stderr so it will appear via the USB
gokmenascioglu 0:a8fa94490a0a 43 * serial port, and then calls exit(1) to die with the blue lights of death.
gokmenascioglu 0:a8fa94490a0a 44 *
gokmenascioglu 0:a8fa94490a0a 45 * Variables:
gokmenascioglu 0:a8fa94490a0a 46 * format - printf-style format string, followed by associated variables
gokmenascioglu 0:a8fa94490a0a 47 */
gokmenascioglu 0:a8fa94490a0a 48 void error(const char* format, ...);
gokmenascioglu 0:a8fa94490a0a 49 #endif
gokmenascioglu 0:a8fa94490a0a 50
gokmenascioglu 0:a8fa94490a0a 51 #include <stdlib.h>
gokmenascioglu 0:a8fa94490a0a 52
gokmenascioglu 0:a8fa94490a0a 53 #ifdef NDEBUG
gokmenascioglu 0:a8fa94490a0a 54 #define error(...) (exit(1))
gokmenascioglu 0:a8fa94490a0a 55 #else
gokmenascioglu 0:a8fa94490a0a 56 #include <stdio.h>
gokmenascioglu 0:a8fa94490a0a 57 #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1))
gokmenascioglu 0:a8fa94490a0a 58 #endif
gokmenascioglu 0:a8fa94490a0a 59
gokmenascioglu 0:a8fa94490a0a 60 #endif