[webkit-dev] Style proposal for branch style for macros

Maciej Stachowiak mjs at apple.com
Mon Apr 21 00:31:07 PDT 2014


On Apr 20, 2014, at 1:19 PM, Mark Rowe <mrowe at apple.com> wrote:

> 
> 
> Won’t compile:
> 
> if (!MAYBE_DEFINED) {
>> }
> 
> if (SOMETHING) {
>     void doSomething() { }
> }
> 
> if (SOMETHING) {
>     #include “Something.h"
> }
> 
> 
> Will result in unintended behavior:
> 
> if (!FOO) {
>> #define BAR
>> }

We clearly can’t use if() to replace #if in general. Let’s assume that we reject a universal proposal of that sort.

However, it seems like the above examples will generally not apply in the case of the switch for assertions being enabled or disabled. Or at least I would not expect it - do you know of such cases in the code?

One worry about Phil’s proposal is that we’d be making asserts enabled/disabled different from handling of other conditional preprocessor macros. One possible way to avoid this is to make asserts enabled/disabled a compile-time constant held in a const global variable instead. That would enforce this style and make it natural.

I am not sure offhand if this is actually viable, but I see no deep reason that assertion control has to be just like the conditional macros we use to avoid submitting code to the compiler that won’t actually compile.

Regards,
Maciej



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20140421/daa39291/attachment.html>


More information about the webkit-dev mailing list