Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: How do I do...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 17 of 18 Topic 26180 of 27679
Post > Topic >>

Re: How do I do generic programming in C?

by Thad Smith <ThadSmith@[EMAIL PROTECTED] > May 14, 2008 at 07:58 PM

Robbie Hatley wrote:
> Greetings, group.  I have a situation at work in which our software
(running
> on a PC) needs to talk to two different versions of our firmware
(running on
> circuit boards in boxes hundreds of feet away, communicating via RS232).
> 
> The two firmware versions (1400 and 1600) are very similar, with 1600
having
> a few more members in each of several key structs used for communicating
and
> storing data.  (Alas, the added members were scattered through the
structs
> by our firmware designer, instead of being added only at the end. 
Sigh.)
> 
> I use the 1600 structs in the PC software to hold data from both
firmware
> types, but for communications, the correct struct MUST be used,
> because the firmware is expecting a data packet of a certain length,
with
> the data members in a certain order.

In the spirit of more choices is better, if the common items are in the 
same order and of the same size, consider defining the lookup table:

setup_t *psetup;	/* dummy pointer */
#define NEWITEM(name) {offsetof(setup_t,name), sizeof(psetup->name) }
const struct {
     size_t  offset;  /* offset of item only in setup_t */
     size_t  size;    /* size of item only in setup_t */
} newitems[] = {     /* new items in order */
     NEWITEM (foo),
     NEWITEM (bar),
     ...
};

Now write functions to copy a memory area, inserting or deleting space at 
the indicated new parameter locations.

On the other hand, once the smaller struct has been defined, and it sounds

as if it has, write the conversion functions once (it sounds like they
have 
been) and forget it.  The newer one may be subject to additions, but that 
doesn't affect the two functions.

-- 
Thad
 




 18 Posts in Topic:
How do I do generic programming in C?
"Robbie Hatley"  2008-05-13 10:21:28 
Re: How do I do generic programming in C?
roberson@[EMAIL PROTECTED  2008-05-13 17:45:12 
Re: How do I do generic programming in C?
viza <tom.viza@[EMAIL   2008-05-13 11:13:00 
Re: How do I do generic programming in C?
"swengineer001@[EMAI  2008-05-13 11:53:29 
Re: How do I do generic programming in C?
Peter Nilsson <airia@[  2008-05-13 15:03:25 
Re: How do I do generic programming in C?
"soscpd@[EMAIL PROTE  2008-05-13 16:28:32 
Re: How do I do generic programming in C?
"Robbie Hatley"  2008-05-14 18:14:42 
Re: How do I do generic programming in C?
Keith Thompson <kst-u@  2008-05-14 19:07:17 
Re: How do I do generic programming in C?
Ian Collins <ian-news@  2008-05-14 11:33:05 
Re: How do I do generic programming in C?
Nick Keighley <nick_ke  2008-05-14 00:46:46 
Re: How do I do generic programming in C?
Ian Collins <ian-news@  2008-05-14 20:05:15 
Re: How do I do generic programming in C?
Flash Gordon <spam@[EM  2008-05-14 22:25:39 
Re: How do I do generic programming in C?
Szabolcs Borsanyi <bor  2008-05-14 01:47:26 
Re: How do I do generic programming in C?
Paul Hsieh <websnarf@[  2008-05-14 15:33:49 
Re: How do I do generic programming in C?
user923005 <dcorbit@[E  2008-05-14 15:52:33 
Re: How do I do generic programming in C?
user923005 <dcorbit@[E  2008-05-14 16:01:17 
Re: How do I do generic programming in C?
Thad Smith <ThadSmith@  2008-05-14 19:58:35 
Re: How do I do generic programming in C?
George Peter Staplin <  2008-05-18 18:08:48 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 21:20:53 CDT 2008.