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

Maciej Stachowiak mjs at apple.com
Mon Apr 21 00:40:12 PDT 2014


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

> 
> It’s also not possible to determine from context alone whether #if or if should be used. When #if is used to remove members or functions you’re then forced to use #if, rather than if, around all uses of those members or functions since the alternative won’t compile.
> 
> An example lifted from Vector.h:
> 
> #if !ASSERT_DISABLED
> template<typename T> struct ValueCheck<Vector<T>> {
>     typedef Vector<T> TraitType;
>     static void checkConsistency(const Vector<T>& v)
>     {
>         v.checkConsistency();
>     }
> };
> #endif
> 
> template<typename T, size_t inlineCapacity, typename OverflowHandler>
> inline void Vector<T, inlineCapacity, OverflowHandler>::checkConsistency()
> {
>     if (!ASSERT_DISABLED) {
>         for (size_t i = 0; i < size(); ++i)
>             ValueCheck<T>::checkConsistency(at(i));
>     }
> }
> 
> 
> This won’t compile with assertions disabled because ValueCheck::checkConsistency doesn’t exist.

Oops, I should have read this email before sending my previous reply. It does seem like using if() exclusively to control assertions won’t work.


On Apr 20, 2014, at 2:02 PM, Filip Pizlo <fpizlo at apple.com> wrote:

> The #if means that the code being guarded isn't indented. I believe that indenting control flow is a good idea. 

This is the main reason I thought the proposal was promising. Note though that we could change our style guide to call for some indentation of #if’s if we wanted to. It is valid C/C++ to do so. The main is that not all text editors have good support for this. 

Regards,
Maciej

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


More information about the webkit-dev mailing list