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

2015-03-03 Thread Roberto E. Vargas Caballero
> alloca() isn't even standard C, that's some black voodoo GNU sorcery > right there. >From alloca(2): There is evedence that the alloca() function appeared in 32V, PWB, PWD.2, 3BSD and 4BSD. There is a man page for it in 4.3BSD. It was common before GNU, and it was not

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

2015-03-03 Thread Roberto E. Vargas Caballero
> On Mon, Mar 2, 2015 at 3:56 PM, Anthony J. Bentley 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-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 mi

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 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 >> create buffer

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

2015-03-02 Thread Evan Gates
Also how strict should the rule be? Is calling functions to define variables when declaring them considered mixing declarations and code? i.e. is this allowed? size_t len = strlen(s); char *buf = emalloc(len + 1); etc. etc. On Mon, Mar 2, 2015 at 3:43 PM, Markus Teich wrote: > Heyho, > > a suc

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 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 broken feature

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 = read

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

[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 AN