This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Unwanted error for long charconsts?

On 23-May-2001, Neil Booth <> 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

 |        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 <>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <>  |     -- the last words of T. S. Garp.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]