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 13 of 18 Topic 26180 of 27670
Post > Topic >>

Re: How do I do generic programming in C?

by Szabolcs Borsanyi <borsanyi@[EMAIL PROTECTED] > May 14, 2008 at 01:47 AM

> 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;
>   (several hundred more lines of "out->foo = in->foo;")
>   return 42;
> } // end ExpandSetupFrom1400()

No, the generic programming capabilities of C are very limited.
But you have some options. Follow your idea with the #include
"function.c",
but if you do not want to include a file twice, copy in with an other
name,
this fits well in a Makefile.

<off>
If you accept a program with several object files, why don't you
create
a source file with this expand function, where the type name is a
macro.
Then in the makefile you compile this expand.c as
expand1.o: expand.c type1.h expand.h
    cc -E -Dtype=type1 -c expand.c

expand2.o: expand.c type.h expand.h
    cc -E -Dtype=type2 -c expand.c
</off>
Your source generator can be the combination of the preprocessor and
make.

Szabolcs
 




 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 Oct 10 22:22:38 CDT 2008.