manpagez: man pages & more
info bigloo
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.1.6.2 Struct and Union types

C struct and Union types can be declared in Bigloo using <struct-type> clauses:

<struct-type> → (struct (<typed-ident> <string>)^+)   
<union-type> → (union (<typed-ident> <string>)^+)

This clause declared a C struct but C structure values cannot be handled by Bigloo. Instead Bigloo is able to handle pointers to C structure. Thus, in order to help the definition of extern types, when a struct named struct is defined, if it does not exists yet, Bigloo automatically defines a type pointer to the structure. This type is named struct*.

When a pointer to a structure type is defined, Bigloo automatically produces functions to manipulate objects of this type. Let us suppose the type definition of struct*:

(type struct
   (struct (id1::type1 name1)
           ...
           (idn::typen namen))

The following functions are created:

Here is an example of structure usage:

(module foo 
   (extern 
     (include "named_point_declaration.h")
     (type named-point 
           (struct (x::double "x")
                   (y::double "y")
                   (name::string "name"))
           "struct named_point")
     (c-print-point::int (named-point*) "ppoint")))

(define (scheme-print-point point)
   (print "point*-name: " point
          " x: " (named-point*-x point)
          " y: " (named-point*-y point)))

(let ((orig (named-point* 0.0 0.0 "orig")))
   (if (named-point*-null? orig)
       (error "bigloo" "cannot allocate point" orig)
       (begin
          (c-print-point orig)
          (scheme-print-point orig))))

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on March 31, 2014 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.