Re: C standard compliance?
- From
David Kastrup <dak@gnu.org>
- Date
- Jan 29, 2014, 20:52 UTC
- Message-ID
- <87eh3q5x42.fsf@fencepost.gnu.org>
- In-Reply-To
- <xmqqwqhiikpg.fsf@gitster.dls.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 13 quoted lines
> David Kastrup <dak@gnu.org> writes: > >> Hi, I am wondering if I may compare pointers with < that have been >> created using different calls of malloc. >> >> The C standard does not allow this (inequalities are only allowed for >> pointers into the same structure) to allow for some cheapskate sort of >> comparison in segmented architectures. > > Hmm... if you were to implement a set of pointers in such a way that > you can cheaply tell if an unknown pointer belongs to that set, you > would use a hashtable, keyed with something that is derived from the > value of the pointer casted to uintptr_t, I would think.
The types intptr_t and uintptr_t are optional in ISO/IEC 9899:1999 (C99). So it would seem that I'd be covering fewer cases rather than more in that manner.
I should think that architectures providing uintptr_t/intptr_t would have very little incentive _not_ to offer pointer inequalities equivalent to either the uintptr_t or intptr_t type conversion.
-- David Kastrup