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

2015-03-03 Thread Martti Kühne
On Tue, Mar 3, 2015 at 12:56 AM, Anthony J. Bentley anth...@cathet.us wrote: Evan Gates writes: 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

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

2015-03-03 Thread Roberto E. Vargas Caballero
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

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

2015-03-02 Thread Evan Gates
This came up recently in talks about style in sbase due to my misunderstanding of Do not mix declarations and code and subsequent addition of the line All variable declarations at top of block in the style guide. It was my understanding that Do not mix declarations and code meant stick to ANSI C

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

2015-03-02 Thread Markus Teich
Evan Gates wrote: Thoughts? Heyho, a suckless piece of code, where this is used would be the manage() function of tabbed.c. I don't mind it to declare variables in inner blocks, so it is clear to the reader that this variable is only intended to be used inside this block and not only the mighty

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

2015-03-02 Thread Evan Gates
On Mon, Mar 2, 2015 at 3:56 PM, Anthony J. Bentley anth...@cathet.us wrote: VLAs are a fundamentally broken feature because they do not allow any error checking. alloca() is the same. -- Anthony J. Bentley But when do you ever do error checking of stack size? Is recursion a fundamentally

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

2015-03-02 Thread Anthony J. Bentley
Evan Gates writes: 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: while ((d =