This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Unwanted error for long charconsts?
- To: Neil Booth <neil at daikokuya dot demon dot co dot uk>
- Subject: Re: Unwanted error for long charconsts?
- From: Fergus Henderson <fjh at cs dot mu dot oz dot au>
- Date: Wed, 23 May 2001 22:57:12 +1000
- Cc: gcc at gcc dot gnu dot org, "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- References: <20010523074306.B16734@daikokuya.demon.co.uk>
On 23-May-2001, Neil Booth <neil@daikokuya.demon.co.uk> wrote:
> Thinking of stuff like 'abcdefg' here.
>
> The standard says:
>
> "The *value* of an integer character constant containing more than one
> character ... is implementation-defined."
>
> We allow stuff like 'ab' as long as it fits in an int, with a warning
> about multi-character charconsts if an appropriate command line option
> was given.
>
> However, if it doesn't fit in an int, we give a hard error with
>
> "character constant too long".
>
> In view of the wording of the standard, this seems wrong to me, and
> we should downgrade the error to a warning.
I disagree. The error is permitted by the standard (see below),
and issuing an error more useful to users than issuing a warning.
The reason that the error is permitted by the standard is that
the value could be implementation-defined to a value that is outside
of the range of int, which then results in a constraint violation
a violation of constraint 6.6#4, just as if you had written
`9999999999999999999999999999999999999999999999999999999999999999999999'.
| 6.4.4 Constants
|
| Syntax
|
| [#1]
|
| constant:
| integer-constant
| floating-constant
| enumeration-constant
| character-constant
|
| Constraints
|
| [#2] The value of a constant shall be in the range of
| representable values for its type.
Note that this constraint is a constraint on programs, not on implementations.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.