[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-gsl] a question on an implementation choice
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Re: [Help-gsl] a question on an implementation choice |
Date: |
Thu, 17 Feb 2011 14:52:30 -0600 |
2011/2/17 Nicolas Bock <address@hidden>:
> 2011/2/17 Jordi Gutiérrez Hermoso <address@hidden>:
>> On 17 February 2011 13:15, Nicolas Bock <address@hidden> wrote:
>>> I am writing a small linear algebra library
>> [snip]
>>> would like to reuse existing code as much as possible.
>>
>> http://arma.sourceforge.net/
>>
>> or the present GSL.
>>
>> There really is no reason to write your own linear algebra library,
>> no matter how small. Well, unless the reason is educational.
> Yes, the reason is educational :)
In that case, it looks like you've discovered C templates. C++
templates were inspired by it and were intended to replace C
templates. Originally templates in C++ were just a mechanism to
replace C preprocessor templates with something that compiler could
understand (as you know, CPP macros aren't seen by the compiler).
Later people realised that C++ templates were their own little
sublanguage of C++ and went to town with them.
As to your original questions...
> * Why did you decide to stick with C and not use C++ and its
> template functionality? Wouldn't that have lead to a cleaner
> implementation?
GSL is part of GNU, and GNU generally dislikes C++. I do think GNU
writes the most beautiful C code out there, which is a rarity. Much
"C" code is more properly called "C/C++", a bizarre Frankenstein
monster of a language, if you ask me. Mind you, I don't mind C++
myself, but I don't like it when C and C++ mix. They are two separate
languages and should stay that way. In my opinion.
> * Was portability an issue?
GNU likes C, because C is sleek.
> * Was there a particular reason to implement the templates in the C
> files with includes to other C files as opposed to in the makefile
> with "-D..." preprocessor arguments?
This is analogous to explicit template instantiation in C++. You could
also do it by passing CPP macros in the compilation line. This is just
a matter of taste.
- Jordi G. H.