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

From: Anthony J. Bentley <anthony_AT_cathet.us>
Date: Mon, 02 Mar 2015 16:56:55 -0700

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 = readdir(dp))) {
> char buf[strlen(path) + strlen(d->d_name) + 1];
> ....
> }

VLAs are a fundamentally broken feature because they do not allow any
error checking. alloca() is the same.

-- 
Anthony J. Bentley
Received on Tue Mar 03 2015 - 00:56:55 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 03 2015 - 01:00:09 CET