[cfe-dev] Preprocessor operators for #error and #warning
David Chisnall
David.Chisnall at cl.cam.ac.uk
Sat Apr 12 02:34:39 PDT 2014
For _Error, you can use C11's _Static_assert():
#define fail(msg) _Static_assert(0, msg)
There's no standard equivalent for #warning, unfortunately.
David
On 11 Apr 2014, at 23:16, Kyle Sluder <kyle at ksluder.com> wrote:
> Hello,
>
> I'd really like to generate #error and #warning tokens from macros. How
> interested would the clang team be in accepting an extension that made
> _Error() and _Warning() operators available, similar to C99's _Pragma()
> operator?
>
> One preferable difference from _Pragma would be for _Error() and
> _Warning() to accept implicit string concatenation. So, for example,
> `#define fail(msg) _Error("failed: " msg)` should workâeven though it
> doesn't work with _Pragma.
>
> Ideally, I'd be able to use printf()-style formatting, since that's what
> my macro gets converted to for debug builds. (I want them to convert to
> compile-time errors in release builds, to prevent shipping code that
> contains that code branch.) But I can understand not wanting to do
> string formatting within the compiler.
>
> --Kyle Sluder
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list