| Re: How do I do generic programming in C? |
|
 |
|
 |
|
 |
|
 |
Group: comp.lang.c · Group Profile
Author: swengineer001swengineer001 Date: May 13, 2008 11:53
>
> 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.
|