Re: [GCC] multi-character constant warning

From: Erwin S. Andreasen (erwin@PIP.DKNET.DK)
Date: 01/05/98


On Mon, 5 Jan 1998, Chris Jacobson wrote:


> I searched through GCC's manpage and EGCS's manpage (I use EGCS btw), but
> couldn't find anything about turning off this warning:
>
> objects.c++:429: warning: multi-character character constant

AFAIR they results aren't defined by the standard: it's up to the compiler
how it will lay out the characters, so on one machine, 'abcd' could be 'a'
<< 24 + 'b' << 16 + 'c' << 8 + 'd', but on another something else
completely.

gcc, however, seems to put them so that your code will work across all
platforms: I tested on a Solaris machine (and I assume you use Linux?)
Unfortunately, there's no native
compiler installed, so I couldn't test that.

If you want to be sure of portability, you could use some macro like:

#define INT(string) (string[0] << 24 + string[1] << 16 + string[2] << 8 + string[3])

And then:

/* Ensure keyword is 3+ chars in len */
switch (INT(keyword_read_from_file))
{

        case INT("Afft"):
        ...
        break;

        case INT("Levl"):
        break;
}


 =============================================================================
Erwin Andreasen   Herlev, Denmark <erwin@pip.dknet.dk>  UNIX System Programmer
<URL:http://www.abandoned.org/drylock/>     <*>         (not speaking for) DDE
 =============================================================================


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST