Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Extending C with GC? Date: Mon, 01 Aug 2016 15:03:14 -0700 Organization: None to speak of Lines: 41 Message-ID: References: <60b33d17-71b7-4ecf-a821-dc641e2673ba@googlegroups.com> <87bn1cxrqp.fsf@news.bourguet.org> <8737moxj9o.fsf@news.bourguet.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="24930"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8wi4ubwVsw4NihaiYWxJc" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:WdLNQJmeQfKchLhgXbLtEVBGDZg= sha1:lRMc/k9zSPkzjPqLJmjmCCwOMeE= Xref: csiph.com comp.lang.c:91536 Jean-Marc Bourguet writes: > Keith Thompson writes: [...] >> Offsetting by a negative value is perfectly valid if the result still >> points into the same object. > > In the context of a GC, I was thinking of negatively offsetting the result > of malloc() or equivalent. It will confuse even the GC which can keep > alive a block with any pointer pointing inside it. That has undefined behavior as far as the C standard is concerned (just computing `ptr-1`, for example, even if it's not used or dereferenced). Once you've done that, even assuming nothing crashes, you no longer have a pointer to the allocated memory and it's perfectly reasonable for a GC system to relcaim it. On the other hand, it might be reasonable in system-specific code to peek at memory before the beginning of a malloc()ed block -- but then you should still keep a copy of the original pointer returned by malloc(). >> As for positive offsets, I can imagine >> that something like: >> >> unsigned char *ptr = malloc(1024); >> assert(ptr != NULL); >> ptr += 32; >> >> might cause headaches for a GC system. (I don't know whether it does so >> in practice.) > > I've seen both cases. Obviously p += 2048 confuse everything I've heard > of. Again, that has undefined behavior. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"