[SSSD] [PATCH] Adding -std=gnu99 flag.

Jakub Hrozek jhrozek at redhat.com
Wed Aug 29 20:05:47 UTC 2012


On Tue, Aug 28, 2012 at 07:07:40PM +0200, Michal Židek wrote:
> On 08/28/2012 06:31 PM, Stephen Gallagher wrote:
> >On Tue, 2012-08-28 at 17:37 +0200, Michal Židek wrote:
> >>On 08/28/2012 04:32 PM, Stephen Gallagher wrote:
> >>
> >>>On Tue, 2012-08-28 at 15:42 +0200, Michal Židek wrote:
> >>>>GCC defaults to gnu89 if no explicit standard was set by -std flag.
> >>>>I think there is no reason to stick to this old standard. It was
> >>>>discussed earlier off-list and if nobody has anything against it,
> >>>>please apply this patch to use gnu99 instead of 89 (for gcc).
> >>>>
> >>>>The patch is attached.
> >>>Ack to the patch, but would you mind identifying what features of gnu99
> >>>we want to take advantage of? Where's the value in this patch?
> >>A feature I really miss is declaration of variables in for cycles.
> >>It is ugly to create variables with names like 'i', 'a' (or whatever)
> >>at function start if all you need is one or two for cycle 'iterators'.
> >>
> >I'd prefer to actually forbid this entirely in our style guidelines.
> >Declaring variables in for-loops is a pretty good way to screw up
> >scoping. I've seen MANY mistakes start this way.
> 
> It is actually one of my favorite features :-) . But I'll survive it if it's
> forbidden by guidelines. You are probably right, that it can be source
> of trouble.
> 

We already use variadic macros for instance, which is a GCC extension that
became part of the C99 standard. I think the same goes for stdbool.h

One of the features I think we could use (with caution in order not to
smash stack) is variable length arrays on the stack. One of the patches
on review used code that looked somewhat like:

char *attributes[3] = { "foo", "bar", "baz" };
char *processed[3];

for (i=0; i < 3; i++) {
    processed[i] = find_and_process(input, attributes[i]);
}

sure it could have been solved by #defining a constant (and to be pedantic
looping extending somearray with NULL sentinel and changing the loop to go
until it hits a sentinel), but in this case using a cost int would have
been more elegant and would allow us to keep the variable length coupled
within the function it is used at.



More information about the sssd-devel mailing list