Re: [PATCH] dir.c: avoid c99 array initialization
- From
Brandon Casey <casey@nrlssc.navy.mil>
- Date
- Aug 28, 2008, 21:45 UTC
- Message-ID
- <4KsgvHQW6DRyM-ubFIcJEblIIJPpRQFHIc-4QMPGe5YzXAU8P5wWCA@cipher.nrlssc.navy.mil>
- In-Reply-To
- <81b0412b0808281412j2a5643ceu49a49cf62002f0be@mail.gmail.com>
Alex Riesen wrote:
Show 23 quoted lines
> 2008/8/28 Brandon Casey <casey@nrlssc.navy.mil>:
>> diff --git a/builtin-cat-file.c b/builtin-cat-file.c
>> index 7441a56..d954c09 100644
>> --- a/builtin-cat-file.c
>> +++ b/builtin-cat-file.c
>> @@ -212,7 +212,7 @@ int cmd_cat_file(int argc, const char **argv, const char *pr
>> int opt = 0, batch = 0;
>> const char *exp_type = NULL, *obj_name = NULL;
>>
>> - const struct option options[] = {
>> + struct option options[] = {
>> OPT_GROUP("<type> can be one of: blob, tree, commit, tag"),
>
> #ifdef HAVE_CONST
> #define gitconst const
> #else
> #define gitconst
> #endif
>
> - const struct option options[] = {
> + gitconst struct option options[] = {
>
> ?The problem is not that the const modifier is unrecognized. You can see in the above patch that the const modifier was not removed from exp_type or obj_name.
I think the warning on line 217 is the most important where it complains about a non-constant initializer, followed by complaints that the left operand must be a modifiable lvalue.
I notice now that some functions have the 'struct option' and all of its parameters declared static. I think this would satisfy the compiler, but then the options would not be reinitialized if the function was called again. Or are cmd_*() functions defined to only ever be called once?
-brandon