PageRenderTime 79ms CodeModel.GetById 22ms app.highlight 1ms RepoModel.GetById 54ms 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
 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
25/** To generate a fatal compile-time error, you can use the pre-processor #error directive.
26 *
27 * @code
28 * #error "That shouldn't have happened!"
29 * @endcode
30 *
31 * If the compiler evaluates this line, it will report the error and stop the compile.
32 *
33 * For example, you could use this to check some user-defined compile-time variables:
34 *
35 * @code
36 * #define NUM_PORTS 7
37 * #if (NUM_PORTS > 4)
38 *     #error "NUM_PORTS must be less than 4"
39 * #endif
40 * @endcode
41 *
42 * Reporting Run-Time Errors:
43 * To generate a fatal run-time error, you can use the mbed error() function.
44 *
45 * @code
46 * error("That shouldn't have happened!");
47 * @endcode
48 *
49 * If the mbed running the program executes this function, it will print the 
50 * message via the USB serial port, and then die with the blue lights of death!
51 *
52 * The message can use printf-style formatting, so you can report variables in the 
53 * message too. For example, you could use this to check a run-time condition:
54 * 
55 * @code
56 * if(x >= 5) {
57 *     error("expected x to be less than 5, but got %d", x);
58 * }
59 * #endcode
60 */
61
62#include <stdlib.h>
63#include "device.h"
64
65#ifdef DEVICE_STDIO_MESSAGES
66    #include <stdio.h>
67    #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1))
68#else
69    #define error(...) (exit(1))
70#endif
71
72#endif