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 2 of 18 Topic 26198 of 26972
Post > Topic >>

Re: How do I do generic programming in C?

by roberson@[EMAIL PROTECTED] (Walter Roberson) May 13, 2008 at 05:45 PM

In article <FKWdnZko3KaPU7TVnZ2dnUVZ_rCtnZ2d@[EMAIL PROTECTED]
>,
Robbie Hatley <see.my.signature@[EMAIL PROTECTED]
> wrote:
>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.

>SO, i had to create "Expand" and "Extract" functions to convert between
>the two versions of the "setup_t" structure, like so:
>
>int ExpandSetupFrom1400 (setup1400_t const *in, setup_t *out)
>{
>  if (!in || !out) return 666;
>
>  memset(out, 0, sizeof(*out));
>
>  out->CoolStages         = in->CoolStages;
>  out->HeatStages         = in->HeatStages;
>  out->StageWidth         = in->StageWidth;
>  out->TimePeriods        = in->TimePeriods;
>  (several hundred more lines of "out->foo = in->foo;")

If you create tables of corresponding structure offsets and element
lengths, then the function bodies could be coded compactly as a loop
doing memory copies.
-- 
  "Is there any thing whereof it may be said, See, this is new? It hath
  been already of old time, which was before us."    -- Ecclesiastes
 




 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 Fri Jul 25 21:48:31 CDT 2008.