assigning ASCII values as const char

I'm trying to write a roguelike using SDL and C++. However, I'm running into a snag. I have a header that has all of my initializing stuff like screen attributes, color identifiers, and some functions that get called all over the place. One of the tiles I want to display is not a basic ascii character, and I'm trying to declare a const char to the ascii value. When I try to compile it kicks me out, and I get the error: "init.h(46): warning C4309: 'initializing' : truncation of constant value" Is there something I'm missing, or can I not assign an ascii value to a const char? I've been searching for a solution to this problem for about an hour and a half, but nothing seems to help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef INIT_H
#define INIT_H

//Screen attributes
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

//world dimensions
const int WORLD_X = 30;
const int WORLD_Y = 30;

//color stuff
const int COLORS = 18;

#define WHITE 0
#define TEAL 1
#define PURPLE 3
#define BLUE 4
#define LT_GRAY 5
#define DK_GRAY 6
#define DK_TEAL 7
#define DK_PURPLE 8
#define DK_BLUE 9
#define YELLOW 10
#define GREEN 11
#define DK_YELLOW 12
#define DK_GREEN 13
#define RED 14
#define DK_RED 15
#define BLACK 16
#define BROWN 17

//tile info
const int NUMTILES = 5;

const int FLOOR_ID = 0;
	const char FLOOR_SYM = '+';
	const int FLOOR_COLOR = LT_GRAY;

const int WALL_ID = 1;
	const char WALL_SYM = '#';
	const int WALL_COLOR = DK_GRAY;

const int CLOSE_DOOR_ID = 2;
	const char CLOSE_DOOR_SYM = 0xDB;
	const int CLOSE_DOOR_COLOR = BROWN;

const int OPEN_DOOR_ID = 3;
	const char OPEN_DOOR_SYM = '/';
	const int OPEN_DOOR_COLOR = BROWN;

const int GRASS_ID = 4;
	const char GRASS_SYM = '.';
	const char GRASS_COLOR = DK_GREEN;

//common functions

Uint32 get_pixel32( int x, int y, SDL_Surface *surface );

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL );

#endif 
closed account (zb0S216C)
It's warning you about this: const char CLOSE_DOOR_SYM = 0xDB; Implicitly, all chars are signed by default, which means their range is: -128 to +127. Therefore, 0xDB in decimal is 219; thus, exceeding the positive range, and ultimately, truncation. To fix this, declare CLOSE_DOOR_SYM as unsigned char. The range for this is: 0 to +255.

Wazzak
Last edited on
Derp, figured it was something stupid like that. Works fine now, thanks for the help.
Topic archived. No new replies allowed.