* Using (SCM)0
@ 2003-10-10 13:33 Ludovic Courtès
2003-10-10 14:38 ` Marius Vollmer
0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2003-10-10 13:33 UTC (permalink / raw)
Hi,
Is there anything wrong with using (SCM)0 as a "special value" in C
code? In other words, is it possible for a "real" SCM object to be
equal to zero, in which case I'd better use SCM_UNDEFINED or some such?
Thanks,
Ludovic.
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Using (SCM)0
2003-10-10 13:33 Using (SCM)0 Ludovic Courtès
@ 2003-10-10 14:38 ` Marius Vollmer
2003-10-10 14:51 ` Ludovic Courtès
0 siblings, 1 reply; 4+ messages in thread
From: Marius Vollmer @ 2003-10-10 14:38 UTC (permalink / raw)
Cc: guile-user
Ludovic Courtès <ludovic.courtes@laas.fr> writes:
> Is there anything wrong with using (SCM)0 as a "special value" in C
> code? In other words, is it possible for a "real" SCM object to be
> equal to zero, in which case I'd better use SCM_UNDEFINED or some such?
Yes. (SCM)0 will be interpreted as a pointer to a cell at address 0,
which will segfault.
You need to be careful with SCM_UNDEFINED as well. I must _never_
reach Scheme code. I.e., you can't put it into pairs, vectors, etc.
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Using (SCM)0
2003-10-10 14:38 ` Marius Vollmer
@ 2003-10-10 14:51 ` Ludovic Courtès
2003-10-10 16:46 ` Marius Vollmer
0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2003-10-10 14:51 UTC (permalink / raw)
Cc: guile-user
On Fri, Oct 10, 2003 at 04:38:56PM +0200, Marius Vollmer wrote:
> Yes. (SCM)0 will be interpreted as a pointer to a cell at address 0,
> which will segfault.
Sure. Actually I meant the following: Suppose I have a structure with
an SCM field and I use calloc () to allocate it; can I write in my code
something like:
if (object->field == (SCM)0)
/* Unitialized, assume there is no "real" Scheme object here */
else
/* Assume object->field is a "real" Scheme object */
Thanks,
Ludovic.
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Using (SCM)0
2003-10-10 14:51 ` Ludovic Courtès
@ 2003-10-10 16:46 ` Marius Vollmer
0 siblings, 0 replies; 4+ messages in thread
From: Marius Vollmer @ 2003-10-10 16:46 UTC (permalink / raw)
Cc: guile-user
Ludovic Courtès <ludovic.courtes@laas.fr> writes:
> Sure. Actually I meant the following: Suppose I have a structure with
> an SCM field and I use calloc () to allocate it; can I write in my code
> something like:
>
> if (object->field == (SCM)0)
> /* Unitialized, assume there is no "real" Scheme object here */
> else
> /* Assume object->field is a "real" Scheme object */
Yes, you can do this (tho it might be easier to initialze the field
with SCM_BOOL_F once, say).
However (and I didn't think about this before) the type SCM is not
necessarily an integer or pointer. It should be treated as opaque.
You need to use SCM_PACK:
if (object->field == SCM_PACK (0))
but there is no real guarantee that SCM_PACK(0) is identical to
all-bits-zero. Hmm. It seems cleaner to avoid testing a SCM for
zero.
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-10-10 16:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-10 13:33 Using (SCM)0 Ludovic Courtès
2003-10-10 14:38 ` Marius Vollmer
2003-10-10 14:51 ` Ludovic Courtès
2003-10-10 16:46 ` Marius Vollmer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).