[macstl-dev] template with C linkage
Glen Low
glen.low at pixelglow.com
Sat Feb 5 20:24:46 WST 2005
On 05/02/2005, at 11:27 AM, David Chilton wrote:
> Glen,
>
> I successfully built and executed the benchmark target in the macstl
> xcode project, and it looks great. Now I'm trying to test
> incorporating macstl into the code for my honors thesis, which relies
> heavily on valarray's read from FITS files, but I can't seem to get
> gcc to build it. I continually get "template with C linkage" errors.
> The same code compiles fine using the standard library valarray.
> below is an example:
>
> #include <macstl/valarray.h>
> using stdext::valarray;
>
> class TestClass
> {
> public:
> static size_t testStatic;
> TestClass(size_t n):index(n) {}
> TestClass():index(0){}
> size_t getindex() { return index;}
> valarray<size_t> testFunc(valarray<TestClass>& input){
> valarray<size_t> d(input.size());
> for(size_t i =0; i<input.size();i++)
> d[i]=input[i];
> return d;
> }
> private:
> size_t index;
> }
> size_t TestClass testStatic = size_t(0);
>
> compile with: gcc -c -o test.o test.cpp
>
> and tons of errors are given
>
> Any suggestions would be appreciated.
>
Thanks for evaluating macstl and joining the list, hope you find both
activities useful!
The program above has a few syntax errors, allow me to correct:
#include <macstl/valarray.h>
using stdext::valarray;
class TestClass
{
public:
static size_t testStatic;
TestClass(size_t n):index(n) {}
TestClass():index(0){}
size_t getindex() { return index;}
valarray<size_t> testFunc(valarray<TestClass>& input){
valarray<size_t> d(input.size());
for(size_t i =0; i<input.size();i++)
d[i]=input[i].getindex(); // no
conversion to size_t, I assume you left out getindex
return d;
}
private:
size_t index;
};
size_t TestClass::testStatic = size_t(0); // needs the ::
On the macstl side there's one minor bug, valarray_vec.h:38 should read
#include <macstl/vec.h>
And the above, if put into main.cpp, should compile cleanly on Apple
gcc 3.3.
I'm not sure where the "template with C linkage" errors are coming
from, perhaps you are compiling a .c file instead of a .cpp file? Or
can you submit an example of the error?
Note that valarray <size_t> is unlikely to be optimized, because size_t
is usually a typedef for long, and only ints are Altivec optimized. On
32-bit gcc, long is 32 bits which is equivalent to an int, but on
64-bit gcc, long is 64 bits which is no longer the size of an int, so I
didn't want to trigger the issue in macstl. (I may do some template
metaprogramming to get 32-bit longs optimized and skip 64-bit longs,
we'll see.)
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com
More information about the macstl-dev
mailing list