[cfe-dev] [clang-format] Indentation of preprocessor directives

Robinson, Paul via cfe-dev cfe-dev at lists.llvm.org
Wed Aug 31 09:22:59 PDT 2016

The # token may be preceded by whitespace; C standard (C99 and C11) 6.10p2 and C++11 chapter 16 p1.

The point of that style is so you can grep for '#include' or '#define' or whatever and be confident you won't miss any.

From: cfe-dev [mailto:cfe-dev-bounces at lists.llvm.org] On Behalf Of Martin J. O'Riordan via cfe-dev
Sent: Wednesday, August 31, 2016 1:21 AM
To: 'Curdeius Curdeius'; 'David Chisnall'
Cc: 'Clang Dev'
Subject: Re: [cfe-dev] [clang-format] Indentation of preprocessor directives

A good point, I’m not 100% sure if it is legal to precede the first ‘#’ with whitespace, though it seems to be commonly accepted.  I’ll have to dig out my ANSI and ISO C documents.

I am not familiar with any Opensource project that uses this style, but I have seen it used in various companies I have done work for in the past; indeed, in one case it was part of their official coding practices.  Interesting if it is not valid ISO C ;-)  I’ve even seen examples such as:

/* comment */ #define foo ...



From: Curdeius Curdeius [mailto:curdeius at gmail.com]
Sent: 31 August 2016 8:42
To: David Chisnall <david.chisnall at cl.cam.ac.uk<mailto:david.chisnall at cl.cam.ac.uk>>; Martin.ORiordan at movidius.com<mailto:Martin.ORiordan at movidius.com>
Cc: Clang Dev <cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>>
Subject: Re: [cfe-dev] [clang-format] Indentation of preprocessor directives

Hi Martin and David, thanks for the interest.

I've had the same impression as David. But certainly, several modern compilers accept indented directives (clang, gcc, mscvc, icc).

Martin, may you be so kind and give some links to projects that use the space-before-hash style, please?

Anyway, it is pretty straightforward to add both styles. Do you have any ideas on naming? Should it be a single option (None, AllAfterHash, AllBeforeHash) or 2 options: one defining when to indent and the other - how to indent?

śr., 31 sie 2016, 08:16 użytkownik David Chisnall <david.chisnall at cl.cam.ac.uk<mailto:david.chisnall at cl.cam.ac.uk>> napisał:
On 30 Aug 2016, at 21:36, Martin J. O'Riordan via cfe-dev <cfe-dev@  tous upór lists.llvm.org<mailto:cfe-dev at lists.llvm.org>> wrote:
> and whitespace indentation preceding the ‘#’ prefixed pre-processing directive:

Is doing this even valid?  I was under the impression that the C preprocessor required the hash to be on column 0.  I’ve certainly had compilers reject code in the past where the preprocessor directives were indented accidentally.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160831/0d45082e/attachment.html>

More information about the cfe-dev mailing list