Re: [exim-dev] C99 coding features

Pàgina inicial
Delete this message
Reply to this message
Autor: Andrew C Aitchison
Data:  
A: Jeremy Harris
CC: exim-dev@exim.org
Assumpte: Re: [exim-dev] C99 coding features
On Thu, 16 Aug 2018, Jeremy Harris via Exim-dev wrote:

> Since f2ed27cf5f (between 4.89 & 4.90) we've documented
> a requirement on C99-capable compilers. This was the
> introduction of specified-initialiser use in the Exim code.
>
> How do people feel about other more-modern C features?
>
> This was triggered by the Postgres hackers ML pointing out
> that C99 permits variable declaration embedded in "for"
> statements, eg:
>
>     for (int i = 0; ...) { ... }

>
> Ref:
>       6.8.5  Iteration statements

>
>       Syntax

>
>               iteration-statement:
>                       while ( expression ) statement
>                       do statement while ( expression ) ;
>                       for ( expr-opt ; expr-opt ; expr-opt ) statement
>                       for ( declaration ; expr-opt ; expr-opt ) statement

>
>
> I'm tempted by that one.


> I don't like mixing declarations with code.


To me the first is an example of the second.
OK, the variable declared in the for goes out of scope after the loop,
which makes it safer, but I am not sure that I can justify one
and not the other.
One of the projects I actually code for requires that variables are
instantiated when they are declared and it is clearer to give a new
variable a value just before it is used than several pages up ...



> Other possibilities mentioned include:
> - variadic macros
> - compound declarations: function((struct x) {1, 2})
>
>
> Comments?


I don't know enough about C99 to comment on its features.

-------

Red Hat / CentOS / Scientific Linux 6 is too old to be a big worry
(especially as they have OpenSSL v1.0.1 which will be a bigger issue)
but on SL6 "man gcc" says
            c99
            c9x
            iso9899:1999
            iso9899:199x
                ISO C99.  Note that this standard is not yet fully supported;
                see <http://gcc.gnu.org/gcc-4.4/c99status.html> for more
                information.  The names c9x and iso9899:199x are deprecated.


Further, gcc v4.7, v4.8, v4.9, v5, v6 and v7 are available for these OSes
from Red Hat / CentOS / Scientific Linux, which can be installed alongside
the default compilers and object code compiled with different versions
can be trivially linked together.

We may need to document compilation on RHEL6 and friends,
but I see no reason for it to stop the use of C99 features.

-- 
Andrew C. Aitchison                    Cambridge, UK
             andrew@???