Function .C — argument setup fails compilation

前端 未结 3 536
伪装坚强ぢ
伪装坚强ぢ 2021-01-19 07:38

I\'m currently learning to call compiled C code in R. Yesterday I created a function for the infinite pi series that when run in R returns a length 1 numeric vector (pi), w

3条回答
  •  无人及你
    2021-01-19 07:47

    fibonacci is declared to take two pointers as arguments, and it doesn't return anything. But in your else block, you're trying to call it with a single integer argument and capture a return value from it.

    Try something like this in your else block:

    int n1 = *n - 1;
    int n2 = *n - 2;
    int ans1;
    int ans2;
    fibonacci(&n1, &ans1);
    fobonacci(&n2, &ans2);
    *ans = ans1 + ans2;
    

    Also, in your else if block, that should be (*n == 0).

提交回复
热议问题