Re: Generics in C
- From: websnarf@xxxxxxxxx
- Date: 13 Jan 2007 11:07:58 -0800
santosh wrote:
ttl_id...@xxxxxxxxx wrote:
This post is about how to get generic modules in a C environment. The
aim is to get close to Ada generics. Using C++ is not an option. It
should all run in a simple C compiler.
When I think of a generic module, it is something that can be used
exactly as it is. The generic H-file and/or C-file, should not have to
be edited AT ALL in order to use it. If it has to be changed in just 1
line, it could possibly still have great reusability properties, but it
is not generic in the sense I mean.
I am going to give a suggestion for a way to do generics, by presenting
5 files as an example. I would very much like comments on how things
could be simplified or extended, but still using only C.
Ok, here we go. Lets say, we want to implement generic powers, by
repeating multiplication. The user of the module have to provide the
type, and a function that performs multiplication on that type.
In my opinion, that defeats the purpose of generic programming.
The purpose of generics is to write algorithms once, and allow them to
apply to different types. The OP's proposal is not as general as it
could be, but it is *one* form of generic programming. I give another
more general approach in the following examples:
http://www.pobox.com/~qed/ll.zip
http://www.pobox.com/~qed/gstack.zip
--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/
.
- References:
- Generics in C
- From: ttl_idiot
- Re: Generics in C
- From: santosh
- Generics in C
- Prev by Date: Re: custom printf() function
- Next by Date: Isn't it time there was a standard align statement?
- Previous by thread: Re: Generics in C
- Next by thread: Re: Generics in C
- Index(es):
Relevant Pages
|