C standard in Unit

Valentin V. Bartenev vbart at nginx.com
Thu Dec 9 01:54:05 UTC 2021

On Thursday, 9 December 2021 03:01:11 MSK Alejandro Colomar (man-pages) wrote:
> Hi Valentin,
> What's the oldest C standard you support?  I'm guessing C89 by what I 
> see.  I didn't see anything in the (Nginx) development guide.

There's no intention to target specific standard.  We just use what most
compilers on relevant platforms are support, and don't use features we
don't like, or don't see benefit.

There are plenty of C99 features used in the code:

 - designated initializers
 - flexible array members
 - inline functions
 - variadic macros

> I see a few 1's where a boolean is expected (and nxt_bool_t defined as 
> an unsigned integer (which IMHO seems a bit dangerous, BTW)), so I guess 
> I shouldn't use C99's true/false, right?

nxt_bool_t is only used for local variables and function parameters.
It serves two purposes:

 1. self-documentation, its name hits that it's expected to be a boolean flag
 2. the underlying type fits into register to squeeze every bit of performance

In structures the boolean flags are stored with optimal size/performance balance
depending on the particular structure size and its field alignments.

Such granular control would be hard to achieve using only C99 booleans.

  wbr, Valentin V. Bartenev

More information about the unit mailing list