I tried to use the #error directive with GCC compiler like this:
#error "The charging pins aren't differing! One pin cannot be used for multiple purposes!"
This says, I should use double quotes, so the argument will be a single string constant and I can use an apostrophe inside of it. However, I want this string to be appeared in the source code in mutiple lines, like:
#error "The charging pins aren't differing!
One pin cannot be used for multiple purposes!"
Then, I got some error messages:
warning: missing terminating " character
#error "The charging pins aren't differing! One pin
error: missing terminating " character
cannot be used for multiple purposes!"
If I insert a blackslash at the end of the first line, the diagnostic message conatains all the whitespaceb between the beginning of the second line and the first word (One). If both lines are strings the diagnostic message shows the inner double quotes.
So the question: How can I achieve this output? (or a similar wihtout double quotes, but the apostrophe included)
#error "The charging pins aren't differing! One pin cannot be used for multiple purposes!"
Unfortunately, you can't have it all.
\
. You can't do this in the middle of a string literal, because then it wouldn't be a valid pre-processing token. This will make the output look weird though, like : error: "hello" "world"
.The relevant translation phases are (from C17 5.1.1.2) executed in this order:
2) Each instance of a backslash character () immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines.
3) The source file is decomposed into preprocessing tokens and sequences of white-space characters (including comments).
4) Preprocessing directives are executed, ...
6) Adjacent string literal tokens are concatenated.
#error
is executed in step 4, earlier than string literal concatenation in step 6.
I personally think the best solution is to skip the apostrophe:
#error The charging pins are not differing! \
One pin cannot be used for multiple purposes!
Slight fix of English and you get the best compromise between readable source and a readable error message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With