How to bind a function pointer in a struct?

Amirouche Boubekki <[email protected]>
Newsgroups gmane.lisp.scheme.bigloo
Message-ID <[email protected]>
I created a small example to learn how to do it.


Using cigloo I generated extern declaration and pasted
inside a bigloo module. Is there a way to include the
output of cigloo inside the module without copy/pasting?

Here is the content of main.scm:

(module foo
     (extern
      ;; beginning of example.h
      (create_abc::ABC* () "create_abc")
      (sum::int (int int) "sum")
      (type s-ABC_ (struct (value::int "value") 
(sum::*int,int,string->int "sum")) "struct ABC_")
      (type int,int,string->int "int ($(int,int,char *))")
      (type *int,int,string->int (function int (int int string)) "int 
((*$)(int,int,char *))")
      (type ABC s-ABC_ "ABC")
      (type ->ABC* "ABC *($())")
      (type int,int->int "int ($(int,int))")
      ;; end of example.h
      )
   (main main))

(define (main x)
   (let ((out (create_abc)))
     (print "total:")
     (print out)))


When I run the command: bigloo main.scm libexample.so -o main

I get the following error:

main.c:19:8: error: unknown type name ‘ABC’
  extern ABC * create_abc();

What I am doing wrong?
example.c (text/x-c, 330 B)
#include <stdlib.h>
#include <stdio.h>

#include "example.h"


int bar(int a, int b, char * message) {
  printf("%s\n", message);
  return a + b + 40;
}

ABC * create_abc() {
  ABC * my_struct = malloc(sizeof(ABC));
  my_struct->value = 42;
  my_struct->sum = bar;
  return my_struct;
}

int sum(int a, int b) {
  return a + b;
}
example.h (text/plain, 131 B)
typedef struct ABC_ {
  int value;
  int (*sum)(int a, int b, char * message);
} ABC;

ABC * create_abc();

int sum(int a, int b);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.