- #1

- 604

- 1

## Main Question or Discussion Point

Hi all,

I'm trying to play about with the GNU scientific library, which means learning how to use function pointers. When I run the code below, I can use function pointers to successfully evaluate two different functions. But I decided to try and look at the function addresses, and instead of the hexidecimal numbers I expected I got the integer "1" for both values. Can someone please explain to me what's going on?

Code:

#include <iostream>

#include <gsl/gsl_sf_bessel.h>

#include <gsl/gsl_math.h>

#include <gsl/gsl_integration.h>

int main()

{

double x = 5.0;

double y = gsl_sf_bessel_J0(x); //me using functions from the GNU scientific library

double z = gsl_sf_bessel_J1(x); //ditto

double t, u;

double (*fpt)(double) = &gsl_sf_bessel_J0;

double (*fpt2)(double) = &gsl_sf_bessel_J1;

t= (*fpt)(x);

u= (*fpt2)(x);

std::cout<< y <<"\n";

std::cout<< z <<"\n";

std::cout<< fpt << "\n";

std::cout<< fpt2 <<"\n";

std::cout<< &gsl_sf_bessel_J0 << "\n";

std::cout<< &gsl_sf_bessel_J1 << "\n";

std::cout<< &x <<"\n";

std::cout<< t <<"\n";

std::cout<< u << "\n";

return 0;

}

And here's the output:

-0.177597

-0.327579

1

1

1

1

0xbfb50420

-0.177597

-0.327579

Thanks.

I'm trying to play about with the GNU scientific library, which means learning how to use function pointers. When I run the code below, I can use function pointers to successfully evaluate two different functions. But I decided to try and look at the function addresses, and instead of the hexidecimal numbers I expected I got the integer "1" for both values. Can someone please explain to me what's going on?

Code:

#include <iostream>

#include <gsl/gsl_sf_bessel.h>

#include <gsl/gsl_math.h>

#include <gsl/gsl_integration.h>

int main()

{

double x = 5.0;

double y = gsl_sf_bessel_J0(x); //me using functions from the GNU scientific library

double z = gsl_sf_bessel_J1(x); //ditto

double t, u;

double (*fpt)(double) = &gsl_sf_bessel_J0;

double (*fpt2)(double) = &gsl_sf_bessel_J1;

t= (*fpt)(x);

u= (*fpt2)(x);

std::cout<< y <<"\n";

std::cout<< z <<"\n";

std::cout<< fpt << "\n";

std::cout<< fpt2 <<"\n";

std::cout<< &gsl_sf_bessel_J0 << "\n";

std::cout<< &gsl_sf_bessel_J1 << "\n";

std::cout<< &x <<"\n";

std::cout<< t <<"\n";

std::cout<< u << "\n";

return 0;

}

And here's the output:

-0.177597

-0.327579

1

1

1

1

0xbfb50420

-0.177597

-0.327579

Thanks.