[Gambas-user] R: How to pass a structure to a C routine

Ru Vuott vuott at ...325...
Wed Aug 19 15:54:18 CEST 2015


Hello Martin,

here an example, so you can see in /tmp the C source-code:

************************************************************

Public Struct punto3d
     x As Float
     Y As Float
     z As Float
End Struct

' double rotate3D(punto3D * pp)
Public Extern rotate3D(point3D As Punto3d) As Float In "/tmp/my_lib"


Public Sub Main()

  Dim p1 As New Punto3d
  Dim ris As Float

  CreaSo()
 
  With p1
    .x = 1.111
    .Y = 2.222
    .z = 3.333
  End With

  ris = rotate3D(p1)

  Print ris

End



Private Procedure CreaSo()   ' Creates C source-code and then file .so of our external C shared library
  
  Dim s As String
  
    s = "struct punto3D {" &
    "\n  double x;" &
    "\n  double y;" &
    "\n  double z;\n};" &
    "\n\n" &
    "\ndouble rotate3D(struct punto3D *pp) {" &
    "\n\n  double d;" &
    "\n  d = pp->x + pp->y + pp->z;" &
    "\n\n  return d;\n}"
    
    File.Save("/tmp/my_lib.c", s)
  
    Shell "gcc -o /tmp/my_lib.so /tmp/my_lib.c -shared" Wait

End

*********************************************************************************




--------------------------------------------
Mer 19/8/15, martin p cristia <tercoide at ...67...> ha scritto:

 Oggetto: [Gambas-user] How to pass a structure to a C routine
 A: gambas-user at lists.sourceforge.net
 Data: Mercoledì 19 agosto 2015, 02:46
 
 Hi:
 
 I need to pass a structure to a C routine
 
 Public Struct punto3d
      x As Float
      Y As Float
      z As Float
 End Struct
 
 and call it like this:
 
 dim p1 as new punto3d
 
 fXnew = rotate3D(p1)
 
 
 how to declare?
 
 Public Extern rotate3D( point3D as ?????) As Float
 
 and how to use the structure in C?
 
 struct punto3D {
      double x;
      double y;
      double z;
 };
 
 
 double rotate3D( punto3D pp)
 .
 .
 .
 
 
 -- Saludos Ing. Martin P Cristia
 
 ------------------------------------------------------------------------------
 _______________________________________________
 Gambas-user mailing list
 Gambas-user at lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user





More information about the User mailing list