ciega
09-20-2007, 02:01 PM
I have an interesting problem. I have access to a NR in C static library (libnr.a). I linked it with code written in c++ (really it's C code with a cpp extension). When I run my program, my results are wrong (i.e., my input is my output). For debugging purposes, I copied the NR code ("smooft.c") over and compiled it in directly. Same answer. Finally, I noticed the routine signature is old c style where parameter types are defined after the signature...
smooft(y,n,pts)
float y[], pts;
int n;
{
so i changed it to: smooft(float *y, int n, float pts).... (*y and y[] were used)
and recompiled. after doing this, I get the correct answer. To check a hunch, I change the file extension from .cpp to .c and recompile. Again, I get the right answer. See attachment.
I would like to know if there is a problem linking "c++" code with the NR in C library? By problem, I mean precision issues, array misalignments, etc.? Everything I've read says the NR code is ANSI compliant. So I assume that I should be able to write code in any language I choose so long as I am able to link with the library. If this is not true, does this mean that I will have to have a library for my C and fortran code and another one for c++ (which may not be an option)?
Thanks in advance!
Marion
smooft(y,n,pts)
float y[], pts;
int n;
{
so i changed it to: smooft(float *y, int n, float pts).... (*y and y[] were used)
and recompiled. after doing this, I get the correct answer. To check a hunch, I change the file extension from .cpp to .c and recompile. Again, I get the right answer. See attachment.
I would like to know if there is a problem linking "c++" code with the NR in C library? By problem, I mean precision issues, array misalignments, etc.? Everything I've read says the NR code is ANSI compliant. So I assume that I should be able to write code in any language I choose so long as I am able to link with the library. If this is not true, does this mean that I will have to have a library for my C and fortran code and another one for c++ (which may not be an option)?
Thanks in advance!
Marion