On Thu, 4 Nov 2010, Vasiliy Kulikov wrote:

> On Thu, Nov 04, 2010 at 16:39 +0100, Julia Lawall wrote:
> > On Thu, 4 Nov 2010, Vasiliy Kulikov wrote:
> > 
> > > Hi,
> > > 
> > > Is there any way to search for C99 array definition with non-constant
> > > size?
> > > 
> > > int x = 2;
> > > ...
> > > int y[x];
> > 
> > I'm not sure what you are asking here.  I tried the following, and it 
> > worked fine:
> 
> Ah, sorry :)  I wanted to ask how to differ good old [const] and C99
> [non-const] arrays.
> 
> Basically, I was just confused with formulating the correct spatch script ;)
> 
> 
> Now I got this version:
> 
> @@
> type T, TT;
> identifier a;
> constant TT s;
> expression E;
> @@
> 
>  T
>  a[ \( s \|
> *E
>  \) ] ;
> --
> 
> IMO it should catch all C99 arrays, correct?

I'm not an expert on what a C99 array is.  But if it is the case where the 
size is not a constant, then this looks fine.  I think  you don't really 
need TT.  You could just say constant s, unless you need the type for 
something else.

> Also, I see that const + const is not const:
> 
> --- main.c    2010-11-04 18:56:47.000000000 +0300
> +++ /tmp/cocci-output-16224-75f1fa-main.c     2010-11-04 18:59:01.000000000 
> +0300
> @@ -11,7 +11,5 @@ main(int argc, char **argv)
>  {
>      int s = 2;
>      int a[sizeof(int)];
> -    int b[s];
> -    int c[1+1];
>      return 0;
>  }
> 
> Obviously 1+1 is constant :)

I think this is something that has gone back and forth.  Is it a big 
problem in practice?

julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to