Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ ROM
➜ Compiling the server
➜ Typecasting issue
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Kelvore
(1 post) Bio
|
Date
| Sat 25 Nov 2006 05:20 AM (UTC) |
Message
| Hello. I'm having a slight problem. I am writing a command editor and I was thinking to simplify the command name/do_function table by making interp.h serve two purposes.
#ifdef DECLARE_DO_FUN
#undef DECLARE_DO_FUN
#endif
#define DECLARE_DO_FUN(do_fun) ( {(char) do_fun, do_fun}, )
const struct cmdfun_type cmdfun_table [] =
{
#include "interp.h"
{"NULL",NULL}
};
#undef DECLARE_DO_FUN
#define DECLARE_DO_FUN(do_fun) void do_fun();
The basic idea is that it will load interp.h converting all the DECLARE_DO_FUN() statements into both a string for the function name ("do_advance") and the function name itself (do_advance). I keep getting this error, however:
interp.h:33: braced-group within expression allowed only inside a function
interp.h:33: `do_advance' undeclared here (not in a function)
interp.h:33: initializer element is not constant
interp.h:33: (near initialization for `cmdfun_table[0]')
interp.h:33: syntax error before ')' token
Any suggestions? I think the error is in my typecasting statement. I can't seem to find a good tip on the subject on the net, however.
| Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Sat 25 Nov 2006 09:29 AM (UTC) |
Message
| There are two problems. Firstly, you don't want the parentheses around your define body; remember that defines are inserted literally and in the array contents you don't want those parentheses.
Secondly, it doesn't make sense to typecast a function pointer to a character. (You'd also want a char*, not just a char, if you could do that in the first place.) You want the stringifier directive. If you enter #do_fun, then it will make a string out of the argument passed in, which is what you want to do.
To read more about this, just look through these:
http://www.google.com/search?&q=preprocessor%20stringify |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
9,556 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top