Fork of the official mbed C/C++ SDK provides the software platform and libraries to build your applications. The fork has the documentation converted to Doxygen format

Dependents:   NervousPuppySprintOne NervousPuppySprint2602 Robot WarehouseBot1 ... more

Fork of mbed by mbed official

Committer:
rolf.meyer@arm.com
Date:
Fri Aug 28 12:10:11 2009 +0000
Revision:
11:1c1ebd0324fa
Child:
27:7110ebee3484
A shiny new version

Who changed what in which revision?

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