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