Re: Dimensions of array parameters

2011-12-06 Thread Ian Lance Taylor
ludovic.cour...@inria.fr (Ludovic Courtès) writes: > Declaring the parameter above as ‘int x[a]’ is valid C99. I fail to see > why this is insufficient for the purposes we discussed. Could you clarify? Sorry, I hadn't realized that C99 permitted that. The standard does clearly state that in pr

Re: Dimensions of array parameters

2011-12-06 Thread Joseph S. Myers
On Tue, 6 Dec 2011, Ludovic Court�s wrote: > > extern void foo (int a, int x[__attribute__ ((dim (a)))]) > > > > could be implemented. > > Why use special syntax for this? It seems to me that int x[a] conveys > the exact same information. No, int x[static a] conveys that information - note the

Re: Dimensions of array parameters

2011-12-06 Thread Ludovic Courtès
Hi, Ian Lance Taylor skribis: > ludovic.cour...@inria.fr (Ludovic Courtès) writes: > >>> Perhaps something like >>> >>> extern void foo (int a, int x[__attribute__ ((dim (a)))]) >>> >>> could be implemented. >> >> Why use special syntax for this? It seems to me that ‘int x[a]’ conveys >> the ex

Re: Dimensions of array parameters

2011-12-06 Thread Ian Lance Taylor
ludovic.cour...@inria.fr (Ludovic Courtès) writes: >> Perhaps something like >> >> extern void foo (int a, int x[__attribute__ ((dim (a)))]) >> >> could be implemented. > > Why use special syntax for this? It seems to me that ‘int x[a]’ conveys > the exact same information. Using special syntax

Re: Dimensions of array parameters

2011-12-06 Thread Ludovic Courtès
Hi, Ian Lance Taylor skribis: > ludovic.cour...@inria.fr (Ludovic Courtès) writes: > >> I understand. However, I’m concerned about keeping the information at >> compile-time. For example: >> >> extern void foo (int a, int x[a]); >> static void bar (void) { >> int x[123]; >> foo (45

Re: Dimensions of array parameters

2011-12-05 Thread Ian Lance Taylor
ludovic.cour...@inria.fr (Ludovic Courtès) writes: > I understand. However, I’m concerned about keeping the information at > compile-time. For example: > > extern void foo (int a, int x[a]); > static void bar (void) { > int x[123]; > foo (456, x); > } > > Here the compiler could em

Re: Dimensions of array parameters

2011-12-05 Thread Ludovic Courtès
Hi, Ian Lance Taylor skribis: > ludovic.cour...@inria.fr (Ludovic Courtès) writes: > >> "Joseph S. Myers" skribis: >> >>> On Fri, 2 Dec 2011, Ludovic Courtès wrote: >>> Is there a way array dimension info could be preserved? >>> >>> Perhaps you could explain the actual problem you are tryi

Re: Dimensions of array parameters

2011-12-02 Thread Ian Lance Taylor
ludovic.cour...@inria.fr (Ludovic Courtès) writes: > "Joseph S. Myers" skribis: > >> On Fri, 2 Dec 2011, Ludovic Courtès wrote: >> >>> Is there a way array dimension info could be preserved? >> >> Perhaps you could explain the actual problem you are trying to solve? > > I’m just thinking that, if

Re: Dimensions of array parameters

2011-12-02 Thread Joseph S. Myers
On Fri, 2 Dec 2011, Ludovic Court�s wrote: > I'm just thinking that, if that information were preserved, GCC could do > static bound checking and/or generate bound checking code. As I noted, that would be contrary to the language semantics unless [static] is used. -- Joseph S. Myers jos...@cod

Re: Dimensions of array parameters

2011-12-02 Thread Ludovic Courtès
Hi, "Joseph S. Myers" skribis: > On Fri, 2 Dec 2011, Ludovic Courtès wrote: > >> Is there a way array dimension info could be preserved? > > Perhaps you could explain the actual problem you are trying to solve? I’m just thinking that, if that information were preserved, GCC could do static boun

Re: Dimensions of array parameters

2011-12-02 Thread Joseph S. Myers
On Fri, 2 Dec 2011, Ludovic Court�s wrote: > Is there a way array dimension info could be preserved? Perhaps you could explain the actual problem you are trying to solve? The value of such a dimension is specified in the C standard to be checked for constraint violations (such as being <= 0) b

Dimensions of array parameters

2011-12-02 Thread Ludovic Courtès
Hello, Parameters that have an array type (fixed-length or variable-length) are internally converted to have a pointer type instead (this is with 4.6.) For example: static int bar (int foo[12]) { return foo[2]; } is turned into: bar (unsigned int x, int * foo) ... Is there a wa