Topic: Another question with const: arrays


Author: comeau@panix.com (Greg Comeau)
Date: 2000/10/13
Raw View
In article <wyt5QgAWhh55Ewg6@ntlworld.com>,
Francis Glassborow  <francisG@robinton.demon.co.uk> wrote:
>In article <8s4e29$l3g$1@panix3.panix.com>, Greg Comeau
><comeau@panix.com> writes
>>Making a local const array *all* 0's certainly does seem like
>>an error in his specific case (I can't imagine any possible use
>>off the top of my head), but as a general course of affairs,
>>I'd prefer a warning then, of course as QoI.
>
>And, without knowing the compiler switches he had set none of us can
>know if the error message was the result of a setting that turned a
>warning into an error.

Agreed (that's always the case).

>I agree with Steve, if the compiler in
>'conforming mode' (yes I know that is impossible for the compiler
>concerned) failed to generate an executable solely because of that code
>it would be an error.

If the last line is "the compiler would be in error",
that's been my point all along.

- Greg
--
Comeau Computing / Comeau C/C++ "so close" 4.2.44 betas NOW AVAILABLE
TRY Comeau C++ ONLINE at http://www.comeaucomputing.com/tryitout
Email: comeau@comeaucomputing.com / WEB: http://www.comeaucomputing.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: 2000/10/11
Raw View
In article <8s249a$s7p$1@panix3.panix.com>, Greg Comeau
<comeau@panix.com> writes
>>Well it is hard to see why you would want a number of immutable copies
>>of a default object. I think the error call is appropriate.
>
>Despite the example that Martin gave (a toy one IMO, I'm sure it's not
>his actual code) I'd be QUITE surprised if the example were not allowed.
>I'd also be amazed if an array or class with a brace initalizer,
>using "sparse" initializers, were disallowed because I const'd it.
>Where in the standard is this disallowed?

That is why I used 'appropriate' rather than 'correct'.


Francis Glassborow      Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: Stephen Clamage <stephen.clamage@sun.com>
Date: 2000/10/12
Raw View
On Wed, 11 Oct 2000 20:33:28 GMT, Francis Glassborow
<francis.glassborow@ntlworld.com> wrote:

>In article <8s249a$s7p$1@panix3.panix.com>, Greg Comeau
><comeau@panix.com> writes
>>>Well it is hard to see why you would want a number of immutable copies
>>>of a default object. I think the error call is appropriate.
>>
>>Despite the example that Martin gave (a toy one IMO, I'm sure it's not
>>his actual code) I'd be QUITE surprised if the example were not allowed.
>>I'd also be amazed if an array or class with a brace initalizer,
>>using "sparse" initializers, were disallowed because I const'd it.
>>Where in the standard is this disallowed?
>
>That is why I used 'appropriate' rather than 'correct'.

Going back to the original example:

 const int ia[ 5 ] = { 0 }; // error

Assuming that "error" means the compiler did not produce a binary, it
is not appropriate. It would mean the compiler rejected a valid
program with well-defined behavior. Maybe the programmer wanted an
array of non-modifiable zero-valued ints. I don't see anything wrong
with that.

---
Steve Clamage, stephen.clamage@sun.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: comeau@panix.com (Greg Comeau)
Date: 2000/10/12
Raw View
In article <zfUpLiAyiM55EwTk@ntlworld.com>,
Francis Glassborow  <francisG@robinton.demon.co.uk> wrote:
>In article <8s249a$s7p$1@panix3.panix.com>, Greg Comeau
><comeau@panix.com> writes
>>>Well it is hard to see why you would want a number of immutable copies
>>>of a default object. I think the error call is appropriate.
>>
>>Despite the example that Martin gave (a toy one IMO, I'm sure it's not
>>his actual code) I'd be QUITE surprised if the example were not allowed.
>>I'd also be amazed if an array or class with a brace initalizer,
>>using "sparse" initializers, were disallowed because I const'd it.
>>Where in the standard is this disallowed?
>
>That is why I used 'appropriate' rather than 'correct'.

Making a local const array *all* 0's certainly does seem like
an error in his specific case (I can't imagine any possible use
off the top of my head), but as a general course of affairs,
I'd prefer a warning then, of course as QoI.

- Greg
--
Comeau Computing / Comeau C/C++ "so close" 4.2.44 betas NOW AVAILABLE
TRY Comeau C++ ONLINE at http://www.comeaucomputing.com/tryitout
Email: comeau@comeaucomputing.com / WEB: http://www.comeaucomputing.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: 2000/10/12
Raw View
In article <8s4e29$l3g$1@panix3.panix.com>, Greg Comeau
<comeau@panix.com> writes
>Making a local const array *all* 0's certainly does seem like
>an error in his specific case (I can't imagine any possible use
>off the top of my head), but as a general course of affairs,
>I'd prefer a warning then, of course as QoI.

And, without knowing the compiler switches he had set none of us can
know if the error message was the result of a setting that turned a
warning into an error. I agree with Steve, if the compiler in
'conforming mode' (yes I know that is impossible for the compiler
concerned) failed to generate an executable solely because of that code
it would be an error.



Francis Glassborow      Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: comeau@panix.com (Greg Comeau)
Date: 2000/10/10
Raw View
In article <39e04c01.2441669@news.nikoma.de>,
Martin Aupperle <MikeAlpha@NoSpam_csi.com> wrote:
>in order to make a program const-correct, I observed that incomplete
>array initializer lists are not possible for const arrays. The
>statement
>
> const int ia[ 5 ] = { 0 }; // error
>
>gives a error message from my compiler (VC6).
>
>Why is this so? Can one of the language experts please explain why the
>normal behavior (of non const arrays) is not allowed here?

One might question why one would have defaults for a const
array instead of just stopping it at that point, but otherwise
it's ok as far as I'm concerned.  Anyway, why not try
http://www.comeaucomputing.com/tryitout too, although
compilers alone shouldn't be used over looking in the standard.
As I recall, a reference cannot be default init'd, but you
don't have that, so unless the above is in some very
odd context that isn't apparent from what you've shown,
I don't see how or why it's rejected.

- Greg
--
Comeau Computing / Comeau C/C++ "so close" 4.2.44 betas NOW AVAILABLE
TRY Comeau C++ ONLINE at http://www.comeaucomputing.com/tryitout
Email: comeau@comeaucomputing.com / WEB: http://www.comeaucomputing.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: 2000/10/11
Raw View
In article <39e04c01.2441669@news.nikoma.de>, Martin Aupperle
<MikeAlpha@NoSpam_csi.com> writes
>Hello,
>in order to make a program const-correct, I observed that incomplete
>array initializer lists are not possible for const arrays. The
>statement
>
>       const int ia[ 5 ] = { 0 }; // error
>
>gives a error message from my compiler (VC6).
>
>Why is this so? Can one of the language experts please explain why the
>normal behavior (of non const arrays) is not allowed here?

Well it is hard to see why you would want a number of immutable copies
of a default object. I think the error call is appropriate.


Francis Glassborow      Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: comeau@panix.com (Greg Comeau)
Date: 2000/10/11
Raw View
In article <$QeaosAdtz45EwKT@ntlworld.com>,
Francis Glassborow  <francisG@robinton.demon.co.uk> wrote:
>In article <39e04c01.2441669@news.nikoma.de>, Martin Aupperle
><MikeAlpha@NoSpam_csi.com> writes
>>in order to make a program const-correct, I observed that incomplete
>>array initializer lists are not possible for const arrays. The
>>statement
>>
>>       const int ia[ 5 ] = { 0 }; // error
>>
>>gives a error message from my compiler (VC6).
>>
>>Why is this so? Can one of the language experts please explain why the
>>normal behavior (of non const arrays) is not allowed here?
>
>Well it is hard to see why you would want a number of immutable copies
>of a default object. I think the error call is appropriate.

Despite the example that Martin gave (a toy one IMO, I'm sure it's not
his actual code) I'd be QUITE surprised if the example were not allowed.
I'd also be amazed if an array or class with a brace initalizer,
using "sparse" initializers, were disallowed because I const'd it.
Where in the standard is this disallowed?

- Greg
--
Comeau Computing / Comeau C/C++ "so close" 4.2.44 betas NOW AVAILABLE
TRY Comeau C++ ONLINE at http://www.comeaucomputing.com/tryitout
Email: comeau@comeaucomputing.com / WEB: http://www.comeaucomputing.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: MikeAlpha@NoSpam_csi.com (Martin Aupperle)
Date: 2000/10/09
Raw View
Hello,
in order to make a program const-correct, I observed that incomplete
array initializer lists are not possible for const arrays. The
statement

 const int ia[ 5 ] = { 0 }; // error

gives a error message from my compiler (VC6).

Why is this so? Can one of the language experts please explain why the
normal behavior (of non const arrays) is not allowed here?

Thanks - Martin

------------------------------------------------
Martin Aupperle
MikeAlpha@NoSpam_csi.com
(remove NoSpam_)
------------------------------------------------

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]