Alex,
I didn't say it's a best way, it's one of possible ways :) I would incline to put those either in new .c file and just call generated functions or in .h file and include it... it's up to you how better to proceed here.
Oh, it's messy indeed. I've got the thing re-written inside of a macro and if you have a typo, since you're using '\' to tell the compiler 'the next line is just more of this one' every line of code is considered the same line. So you get errors like 'unexpected "." on line xxx' which could be any of the 100 or so lines of macro code. Oh, and you can't use C++ style '//' comments and C style '/* */' comments have to end with '\' on each line as well. Yick. Anyway, I've got it started as I said. The ##name token pasting or whatever it's called is giving me an issue though. Here is a bit of my code:
---
#define xyz_pdu(name) \
static SMPP_PDU *msg_to_##name_pdu(SMPP *smpp, Msg *msg, SMPP_PDU *pdu) \
{ \
struct name cmd = pdu->u.name; \
\
cmd.source_addr = octstr_duplicate(msg->sms.sender); \...
return pdu; \ }
xyz_pdu(data_sm); xyz_pdu(submit_sm);
---
and here is the errors I'm getting:
---
gw/smsc/smsc_smpp.c:719: error: redefinition of `msg_to_name_pdu'
gw/smsc/smsc_smpp.c:718: error: `msg_to_name_pdu' previously defined here
gw/smsc/smsc_smpp.c: In function `msg_to_pdu':
gw/smsc/smsc_smpp.c:737: warning: return makes pointer from integer without a cast
gw/smsc/smsc_smpp.c:743: warning: return makes pointer from integer without a cast
make: *** [gw/smsc/smsc_smpp.o] Error 1
---
Now I know from experience the 'pointer from integer' crap is because it's assuming an int return on an 'undefined' function as the actual ##name thing isn't working (ie. the error about 'previously defined'). So I don't need an explanation on that. I just need to know if I'm doing something wrong on my ##name above that's keeping it from doing the token pasting and creating instead msg_to_data_sm_pdu and msg_to_submit_sm_pdu functions for me.
As an aside, is there any way I could use 'offsetof' to find the address of the various bits of the union instead? I tried without any luck. Here is a page describing 'offsetof':
http://www.embedded.com/showArticle.jhtml?articleID=18312031
I tried to fake it with code like the following:
((Octstr*)offsetof(pdu, source_addr)) = octstr_duplicate(msg->sms.sender);
without any luck. <sigh>
Btw. Thanks for you contribution!
I haven't actually contributed anything yet. Wait until the code works for a 'thanks'. :P
Jon
