Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: multidimensional heap arrays |
| Date | 2011-04-27 10:19 +1200 |
| Message-ID | <91ouo6Fq9bU12@mid.individual.net> (permalink) |
| References | (4 earlier) <0.ba05a251a5fe8eed2ac7.20110426121957BST.8739l5dztu.fsf@bsb.me.uk> <91noctFq9bU7@mid.individual.net> <0.bece330a32ff7f1d21e3.20110426210623BST.87r58odbgg.fsf@bsb.me.uk> <91oq24Fq9bU9@mid.individual.net> <0.967ba25c6450811178a3.20110426224949BST.87liywd6o2.fsf@bsb.me.uk> |
On 04/27/11 09:49 AM, Ben Bacarisse wrote:
> Ian Collins<ian-news@hotmail.com> writes:
>
>> On 04/27/11 08:06 AM, Ben Bacarisse wrote:
>>> Ian Collins<ian-news@hotmail.com> writes:
>>>
>>>> On 04/26/11 11:19 PM, Ben Bacarisse wrote:
>>>>> Francois Grieu<fgrieu@gmail.com> writes:
>>>>>
>>>>>> On 26/04/2011 06:19, Anand Hariharan wrote:
>>>>>
>>>>>>> or will the 'arr' in the following code be a 'plain and ordinary'
>>>>>>> array ...
>>>>>>>
>>>>>>> const int ncol = 5;
>>>>>>> int arr[ncol];
>>>>>
>>>>> The former. This is a VLA and will remain so in C1x.
>>>>>
>>>>>> I'm genuinely wondering: is ncol a "constant expression" ?
>>>>>
>>>>> It might be in that an implementation can define its own forms of
>>>>> constant expression, but it does not meet the standard's minimum
>>>>> requirements to be an "integer constant expression" (which is what is
>>>>> required to declare a non-VL array).
>>>>
>>>> Which is really silly. I do wish they could fix that and bring it in
>>>> line with C++. But I guess adding VLAs shot that idea in the foot.
>>>
>>> I too would like to have seen the same constant expression definition
>>> between C++ and C but I don't see how C's VLAs got in the way of that.
>>
>> The code above sums it up, if ncol is an "integer constant expression"
>> is arr an array, or a VLA?
>
> Yes, a change in what constitutes an integer const expression would
> change some VLAs to plain arrays but I don't think that counts as
> "[shooting] that idea in the foot".
>
>> Would it be acceptable for a language change to change (all be it
>> subtly) the behaviour of existing code?
>
> I think so, in part because I am not certain that one can rely on the
> current behaviour. An implementation that permitted initialised const
> variables to appear in constant expressions would already have the "new"
> semantics (at least I think it would) so it could be argued that the
> code was skating on thin ice already.
>
> In addition, the change is very sight. A program that behaves
> differently were a VLA to become a plain arrays is already something of
> a monster. I can come up with such programs, but they are all very
> contrived. There may be a natural example, but it seems unlikely.
I was trying to come up with one and the first example I conjured up
surprised me:
typedef char C[16];
void f( C* c ) {}
int main(void)
{
char c[16];
f( &c );
const unsigned n = 15;
char cc[n];
f( &cc );
}
Compiles fine as c99 (which was the surprise), but fails as C++ (type
mismatch). What did surprise me was the VLA type matching even though
the size differed. Changing the declaration of cc to cc[15] did produce
the expected compiler warnings.
--
Ian Collins
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
multidimensional heap arrays Jack Boot <jackboot@mailinator.com> - 2011-04-25 19:36 +0000
Re: multidimensional heap arrays Francois Grieu <fgrieu@gmail.com> - 2011-04-25 23:16 +0200
Re: multidimensional heap arrays Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-04-25 22:35 +0100
Re: multidimensional heap arrays Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2011-04-25 21:19 -0700
Re: multidimensional heap arrays Francois Grieu <fgrieu@gmail.com> - 2011-04-26 08:19 +0200
Re: multidimensional heap arrays Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-04-26 12:19 +0100
Re: multidimensional heap arrays Ian Collins <ian-news@hotmail.com> - 2011-04-26 23:25 +1200
Re: multidimensional heap arrays Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-04-26 21:06 +0100
Re: multidimensional heap arrays Ian Collins <ian-news@hotmail.com> - 2011-04-27 08:59 +1200
Re: multidimensional heap arrays Keith Thompson <kst-u@mib.org> - 2011-04-26 14:39 -0700
Re: multidimensional heap arrays Ian Collins <ian-news@hotmail.com> - 2011-04-27 10:03 +1200
Re: multidimensional heap arrays Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-04-26 23:41 +0100
Re: multidimensional heap arrays Keith Thompson <kst-u@mib.org> - 2011-04-26 16:33 -0700
Re: multidimensional heap arrays Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-04-27 04:05 +0100
Re: multidimensional heap arrays Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-04-26 22:49 +0100
Re: multidimensional heap arrays Ian Collins <ian-news@hotmail.com> - 2011-04-27 10:19 +1200
Re: multidimensional heap arrays Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-04-27 00:38 +0100
Re: multidimensional heap arrays Ian Collins <ian-news@hotmail.com> - 2011-04-27 11:48 +1200
Re: multidimensional heap arrays Keith Thompson <kst-u@mib.org> - 2011-04-26 17:38 -0700
Re: multidimensional heap arrays Ian Collins <ian-news@hotmail.com> - 2011-04-27 13:08 +1200
Re: multidimensional heap arrays Tim Rentsch <txr@alumni.caltech.edu> - 2011-04-26 18:31 -0700
Re: multidimensional heap arrays Ian Collins <ian-news@hotmail.com> - 2011-04-27 14:01 +1200
Re: multidimensional heap arrays Tim Rentsch <txr@alumni.caltech.edu> - 2011-04-27 00:04 -0700
Re: multidimensional heap arrays Ian Collins <ian-news@hotmail.com> - 2011-04-27 19:58 +1200
Re: multidimensional heap arrays Ian Collins <ian-news@hotmail.com> - 2011-04-27 20:03 +1200
Re: multidimensional heap arrays Keith Thompson <kst-u@mib.org> - 2011-04-27 00:03 -0700
Re: multidimensional heap arrays Tim Rentsch <txr@alumni.caltech.edu> - 2011-04-26 18:20 -0700
Re: multidimensional heap arrays Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-04-27 03:59 +0100
Re: multidimensional heap arrays Tim Rentsch <txr@alumni.caltech.edu> - 2011-04-27 00:24 -0700
Re: multidimensional heap arrays "io_x" <a@b.c.invalid> - 2011-04-26 09:42 +0200
Re: multidimensional heap arrays Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-04-25 20:50 -0400
Re: multidimensional heap arrays James Kuyper <jameskuyper@verizon.net> - 2011-04-25 22:57 -0400
csiph-web