Re: Variable length arrays proposal



Randy Howard wrote:

On Wed, 29 Jun 2005 11:29:03 -0500, jacob navia wrote
(in article <42c2cc50$0$1217$8fcfb975@xxxxxxxxxxxxxxx>):


Proposal:

Allow the following syntax:

	typedef struct {
		int length;
		char data[length];
	} String;
This would indicate to the compiler that the "data" array
will have the length indicated by the "length" member. This
would allow to easily write code that automatically writes the
structure to disk, and allow that the compiler generates code
to check for index errors when accessing the "data" array.

Constraints:

The index should be a structure member of integer type.


Along with the other comments, even if it went through, the index should be size_t, not int.

I see no reason that length couldn't be any signed or unsigned integer type. We aren't constrained to only have index expressions of type size_t.


That said, I think the proposal goes beyond the spirit of C.

Thad

.



Relevant Pages

  • Re: Size of a structure : Structure Padding
    ... int i1; // 4 ... According to the rules of structure padding shouldn't the size of the ... it shouldn't be 28 bytes for a 32-bit compiler. ... It may very well be that the second member of your structure, ...
    (comp.lang.c)
  • Re: C++ in ternms of C
    ... >A class has its member variables, ... > int b, c, d; ... >the compiler performs these checks to tell us that our code conforms to the ... >design specification of the class (for example, not changing the member ...
    (microsoft.public.vc.language)
  • Re: Can nested class members access private members of nesting class?
    ... > then accessed a member of the other. ... List is supposed to be Container. ... "enclose" without being declared a friend, but my compiler doesn't say ...
    (comp.lang.cpp)
  • Re: Superbasic efficiency question
    ... > have members such as int a, b, c, d, e or a single member such as int ... perhaps the compiler placed the values in registers. ...
    (comp.lang.cpp)
  • Re: Superbasic efficiency question
    ... > have members such as int a, b, c, d, e or a single member such as int ... perhaps the compiler placed the values in registers. ...
    (comp.lang.c)