style: cpp indentation

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Jun 2 07:10:10 UTC 2014


On 2014-05-30 00:14, Joel Sherrill wrote:
> On 5/29/2014 3:47 PM, Gedare Bloom wrote:
>> >Hi,
>> >
>> >Any guidance on whether we should have a style rule about CPP
>> >directives? Mainly this is for #ifdef #endif guards for conditional
>> >code compilation. There are two options based on what exists in the
>> >cpukit today:
>> >
>> >1) Preprocessor directives within indented code should be one nesting
>> >level outside of the affected code.
>> >2) Preprocessor directives within indented code should not be indented.
>> >
>> >You can see an example of both, e.g. at
>> >cpukit/score/src/threaddispatch.c:111-132 just to pick one.
> (1) is historical
> (2) is newer
>
> Personally, I lean to (2) and may be the guilty party for much of that code.
>
> Older C tended to always put the cpp #directives in the 1st column. Whether
> there were broken compilers or we just followed K&R style, I don't know.
>
> I think style (2) treats the conditionals like C logic and following the
> same rules
> seems to help.
>
> But this is one of those things where I am sure I wrote in style (1) for
> years
> and somewhere was exposed to (2) and started using it.

I am happy with both variants.

>
> FWIW The GNU Ada run-time for RTEMS should go back to the default of using
> POSIX keys. That will fix it for SMP and eliminate some of this code.

Since the Ada self context is part of Thread_Control you can also use something 
like __getreent().

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.



More information about the devel mailing list