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 4 of 18 Topic 26198 of 26955
Post > Topic >>

Re: How do I do generic programming in C?

by "swengineer001@[EMAIL PROTECTED] " <swengineer001@[EMAIL PROTECTED] > May 13, 2008 at 11:53 AM

>
> So... is there any way of emulating templates in C?
> Or do I just have to live with duplicate functions?
>
> --
> Cheers,
> Robbie Hatley
> lonewolf aatt well dott com
> www dott well dott com slant user slant lonewolf slant

Why not use a structure containing a type value and a union of the 2
structures that can be passed:

typedef enum
{
    firststructure = 1,
    secondstructure = 2
} MyStructures;

typedef struct
{
   ..........
} structure1;
typedef struct
{
    ........
} structure2;

typedef union
{
    structure1 first;
    structure2 second;
} MyUnion;

typedef struct
{
    MyStructures structur_type;
    MyUnion TheStructure;
} TheArgument;

Obviously you would want to name everything appropriately.
 




 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 Thu Jul 24 2:43:50 CDT 2008.