guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: exposing C struct contents in Scheme


From: Robert Uhl
Subject: Re: exposing C struct contents in Scheme
Date: 28 Apr 2003 18:41:33 -0600
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2

Rob Browning <address@hidden> writes:
> 
> > This is what I've done, partly because I'm writing in gtk+ and
> > already have to write getters & setters in C; the burden of writing
> > them in guile was negligible.  Even in C you might find that your
> > library is more robust if you always use functions (they can really
> > be macros...)  to get/set structure members.
> 
> And it makes it easy if you ever need to instrument public access to
> the struct, or add locking, or whatever.

Exactly.  It's not the old days when it was worth the savings to twiddle
data directly.  Except, of course, when it is:-)

It can be pretty ugly and verbose, but even that can be worth it in
terms of run-time error checking &c.:

  TravMapobject* planet;
  ...
  trav_mapobject_set_name(planet, "Earth");
  trav_planet_set_diameter(TRAV_PLANET(planet), 4.3);

rather than:

  TravPlanet* planet;
  ...
  if (planet && planet->name)
    free(planet->name); // hope that it was allocated with malloc...
  (void)strcpy(planet->name, "Earth");
  planet->diameter = 4.3;

which also loses because one must retrieve a planet's name differently
than a galaxy's (the offsets may be different), which can be a pain for
some generic functions.

-- 
Robert Uhl <address@hidden>
Come receive the light from the unwaning light,
And glorify Christ Who rose from the dead.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]