Welcome, Guest. Please login or register.

Author Topic: multi-character character constants in C++  (Read 5181 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline SidewinderTopic starter

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 241
    • Show all replies
    • http://www.liquido2.com
multi-character character constants in C++
« on: April 05, 2003, 10:08:31 PM »
I have some code that I'm trying to port using StormC 4.  It compiles for the most part, but I get litterally thousands of warnings about multi-character character constants.  What I have is basically somthing like this:

enum
{

JOHN_NAME = 'john',
FRED_NAME = 'fred',
MIKE_NAME = 'mike',
ANNE_NAME = 'anne'

}

I gather that since enums are 4 byte integers each character in the character constant is supposed to be copied to the corresponding byte in the enum.  So you have essentially an array of 4 bytes that is cast as an int.

Is there any other way to express this that would avoid giving me so many warnings and errors?

Thanks,
Sidewinder
 

Offline SidewinderTopic starter

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 241
    • Show all replies
    • http://www.liquido2.com
Re: multi-character character constants in C++
« Reply #1 on: April 06, 2003, 12:44:02 AM »
You see, the problem is that it's not my code.  It's part of the POVRay ray tracing package which is supposed to be portable code.  There are litterally thousands of occurences of this error.  I guess I'll just ignore it and see what happens.
Sidewinder
 

Offline SidewinderTopic starter

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 241
    • Show all replies
    • http://www.liquido2.com
Re: multi-character character constants in C++
« Reply #2 on: April 06, 2003, 04:58:55 PM »
Quote

If you can be bothered, you could try an explicit cast to long - eg

JOHN_NAME = (long)'john'

That's still not particularly portable but it might just shut the compiler up...

-edit-

Just noticed: long john


"long john" Very nice!  Well I tried the cast, but no joy.  It seems that the compiler isn't complaining about the assignment but rather about the fact that there is more than one character between the single quotes.  The code compiles ok however, just with about 3-4 thousand warnings.  :-)
Sidewinder