Re: [dev] [style] variable declaration locations and varriable length arrays vs malloc

From: Roberto E. Vargas Caballero <>
Date: Tue, 3 Mar 2015 11:03:40 +0100

> It was my understanding that "Do not mix declarations and code" meant
> stick to ANSI C declarations. ANSI C allows declarations of variables
> only at the top of blocks, but allows them in any block so they aren't
> relegated to the top of the function. It was pointed out to me that
> "Do not mix declarations and code" is stricter and means that all
> variables must be declared at the top of the function.

Well I don't understand it in this way, for me it means
don't declare variables after an expression (initializers
don't count as expressions).

> Declaring variables at the top of a block, as opposed to top of the
> function has a few uses, but the most useful (in my limited
> experience) is combining it with C99's variable length arrays to
> create buffers without calls to malloc/free. For example:

I like declare variables at the beginning of each block,
but there are another suckless developer don't like.
In the Plan9 style initializators are forbiden, but for me
and for common UNIX styles are fine. I think it is
a point where each project can take different

Received on Tue Mar 03 2015 - 11:03:40 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 03 2015 - 11:12:08 CET