07 Apr, 2014, lilmike wrote in the 1st comment:
Votes: 0
Hi all (and especially KaVir),
I was trying to implement your snipet into a custom mud based on Aspen I'm building, and found an error in protocol.h that i think may have to do with it being c++, or perhaps g++ 4.7 supporting c++11, not sure.
Anyway, when I compile:

protocol.h:100:4: error: expected identifier before 'false'                     
protocol.h:100:4: error: expected '}' before 'false'
protocol.h:100:4: error: expected unqualified-id before 'false'
protocol.h:102:1: error: expected declaration before '}' token


Hope y'all can help :).
-Michael.
07 Apr, 2014, KaVir wrote in the 2nd comment:
Votes: 0
It's because the snippet is written in C, not C++. C++ already has its own bool type, so use that instead.
07 Apr, 2014, lilmike wrote in the 3rd comment:
Votes: 0
Hey,
Thanks. I just substituted bool for bool_t and fixed that. However, one problem I am having now that I hope someone can help with:
I need to include an instance of protocol_t with each player, so put protocol_t* pProtocol in my class player. I forward declared struct protocol_t and class player in the opposite files, respectively as i obviously can't include protocol.h in player.h and player.h in protocol.h. heh. So now it's saying that there's a conflicting definition of protocol_t as I'm forward declaring protocol_t in player.h, but also including protocol.h in player.cpp, which makes there be two definitions, the forward one and the one in protocol.h.
Not sure how to handle this as player.cpp needs to know about the protocol format, while player.h doesn't, but still needs a forward definition… but obviously player.cpp needs to include player.h… leading to duplicate definitions.
I think there's something similar in protocol.cpp, as it also included player.h and
Thanks,
-Michael.
07 Apr, 2014, KaVir wrote in the 4th comment:
Votes: 0
You don't need to add any #includes to protocol.h, it doesn't care what's in player.h - so there shouldn't be any circular dependencies.

The forward declaration should also work, as long as you're only using pointers or references.
07 Apr, 2014, lilmike wrote in the 5th comment:
Votes: 0
Hi,
I see what you mean. I just have a forward declaration in player.h and protocol.h:
struct protocol_t;
class player;

but now my problem, if I can try to explain it a little better:

player.cpp both includes player.h and protocol.h, as player.cpp needs to know the makeup of class player, and also needs to know the makeup of protocol_t and its functions related to it.
This causes a problem, as player.h has forward declared protocol_t, but protocol.h explicitly defines it. This gives me an error. In addition protocol.h has forward declared class player, giving another error.
The same basically happens in protocol.cpp, as protocol.cpp needs to know the functions and structs in protocol.h, but also needs to know the player class makeup, so including player.h and protocol.h leads to two declarations of class player and struct protocol_t, one forward and one not.
Does this make any sense?
Thanks,
-Michael.
07 Apr, 2014, lilmike wrote in the 6th comment:
Votes: 0
Hi,
I think I have it fixed. I didn't realize you can't forward declare anonymous structs, so I changed typedef struct {

} protocol_t;
to struct protocol_t {

};

Thanks,
-Michael.
07 Apr, 2014, lilmike wrote in the 7th comment:
Votes: 0
Hi,
One other thing I noticed:
Alot of the char* x = malloc(…); are erroring out. I'm not sure if that's a c++ detail, if so ignore this but… when I put (char*)(malloc(…));, it works.
-Michael.
07 Apr, 2014, Pymeus wrote in the 8th comment:
Votes: 0
C++ requires an explicit cast to convert a void pointer to another pointer type; C doesn't.
07 Apr, 2014, KaVir wrote in the 9th comment:
Votes: 0
Pymeus said:
C++ requires an explicit cast to convert a void pointer to another pointer type; C doesn't.

This. In C, void * is automatically and safely promoted to the appropriate type, and casting it could potentially hide an error (such as a missing include).

However if you're converting the snippet to C++, I would recommend against using malloc().
07 Apr, 2014, lilmike wrote in the 10th comment:
Votes: 0
Hi,
The only reason I had to make it a .cpp file was because my other files, including player, socket, etc, all of which need to be used somewhere in the snippet, are in c++. Therefore, if I include player.h in protocol.c, it would complain because it defined a class.
Anyway, I think I've got it working (after about half a day of debugging my code :P).
Thanks,
-Michael.
0.0/10