A
Alexander Farber
Hi,
I have a UNIX-server written in C, which exchanges messages
with Java clients. In the message the 1 byte is its length,
the 2nd a player number and the 3rd byte is an event id:
/* 0. byte: Total message length in bytes (inlcuding this byte) */
/* 1. byte: Player number (0, 1 or 2) */
/* 2. byte: Event id (10 - 22) */
/* 3.-255.: Argument (252 bytes or 126 big-endian UTF-16 chars) */
typedef unsigned char byte;
typedef struct {
byte len,
num,
id,
arg[MAXARG];
} msg;
For the event ids I currently use #defines:
#define PREF_NAME 10
#define PREF_PASS 11
#define PREF_CHAT 12
#define PREF_CARD 13
But I would actually prefer to use enums instead, something like:
enum event_id {
PREF_NAME = 10,
PREF_PASS,
PREF_CHAT,
PREF_CARD
}
However enums are integers, aren't they? Could
I somehow specify that my enums are 8 bit long only?
One more question: how do you use typedef's with enum's?
I've tried to change this code:
enum direction {
FROM,
TO
};
void print_node(unsigned i, unsigned j, enum direction dir, const node
*np);
To the following, but get strange unrelated error messages
(I suspect that I declare a variable "direction" there instead):
typedef enum {
FROM,
TO
} direction;
void print_node(unsigned i, unsigned j, direction dir, const node *np);
Thank you
Alex
PS: I'm using gcc 3.3.5 on OpenBSD 3.7.
I have a UNIX-server written in C, which exchanges messages
with Java clients. In the message the 1 byte is its length,
the 2nd a player number and the 3rd byte is an event id:
/* 0. byte: Total message length in bytes (inlcuding this byte) */
/* 1. byte: Player number (0, 1 or 2) */
/* 2. byte: Event id (10 - 22) */
/* 3.-255.: Argument (252 bytes or 126 big-endian UTF-16 chars) */
typedef unsigned char byte;
typedef struct {
byte len,
num,
id,
arg[MAXARG];
} msg;
For the event ids I currently use #defines:
#define PREF_NAME 10
#define PREF_PASS 11
#define PREF_CHAT 12
#define PREF_CARD 13
But I would actually prefer to use enums instead, something like:
enum event_id {
PREF_NAME = 10,
PREF_PASS,
PREF_CHAT,
PREF_CARD
}
However enums are integers, aren't they? Could
I somehow specify that my enums are 8 bit long only?
One more question: how do you use typedef's with enum's?
I've tried to change this code:
enum direction {
FROM,
TO
};
void print_node(unsigned i, unsigned j, enum direction dir, const node
*np);
To the following, but get strange unrelated error messages
(I suspect that I declare a variable "direction" there instead):
typedef enum {
FROM,
TO
} direction;
void print_node(unsigned i, unsigned j, direction dir, const node *np);
Thank you
Alex
PS: I'm using gcc 3.3.5 on OpenBSD 3.7.