Re: Generics in C



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/

.



Relevant Pages

  • Re: Generics Question
    ... I am asking for academic reasons. ... His reasons for studying generics need not be the ... same as the language designers' purpose for providing generics, ...
    (microsoft.public.dotnet.framework.clr)
  • Re: .NET 2.0 to be launched on Nov 8
    ... >> I do not see the purpose here, with ordinary strong typed containers. ... > First of all I don't use C++, I use generics in Pascal. ... > Also the .net generics are definable at RUNTIME... ...
    (borland.public.delphi.non-technical)
  • Class Field in list.
    ... For the purpose i have created ... Now I want to design the class in such a way that when I type ... im using dotnet 2.0 and know little about generics. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ReadOnlyCollectionBase, Collection, DictionaryBase in VB2005 ?
    ... I understand that the only purpose of those classes ... was to create custom-made, strongly-typed collections, which isn't ... necessary anymore with generics, correct? ...
    (microsoft.public.dotnet.languages.vb)
  • Short Steps Toward Generic Programming: Introduction
    ... since I have promised to publicize the present crop of Fortran ... more detail) my proposal for generic programming. ... Another form of polymorphism that is simle in another way is called ... similar to the ad-hoc generics. ...
    (comp.lang.fortran)