Re: [GENERAL] Linking in sin() as a C function

Поиск
Список
Период
Сортировка
От Sevo Stille
Тема Re: [GENERAL] Linking in sin() as a C function
Дата
Msg-id 38981237.91256F11@ip23.net
обсуждение исходный текст
Ответ на Re: [GENERAL] Linking in sin() as a C function  (mathprof@bigfoot.com)
Список pgsql-general
mathprof@bigfoot.com wrote:
>
> Thanks! Based on this, I created a file called "test.c" as follows:
>
> #include <math.h>
> float pg_sin(float *x) {return(sin(*x));}
>
> and compiled it using: "gcc test.c -lm -shared" to create a shared object
> file. I then tried the same steps as below (substituting
> "/usr/lib/libm.so" with the path to my "a.out" file created by gcc), but
> this still didn't work? I'm getting different wrong values, but they're
> still wrong nonetheless?


The return has to be a pointer too. Try:

#include <math.h>
#include "postgres.h"
#include "utils/palloc.h"

float *pg_sin(float *x){
    float *f = (float *)palloc(sizeof(float));
     *f = sin(*x);
    return f;
}


Sevo

--
Sevo Stille
sevo@ip23.net

В списке pgsql-general по дате отправления:

Предыдущее
От: Adriaan Joubert
Дата:
Сообщение: Re: [GENERAL] PL/pgSQL syntax/usage question
Следующее
От: Patrick Welche
Дата:
Сообщение: Re: [GENERAL] VACUUM ANALYSE