git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: C standard compliance?

From
Philip Oakley <philipoakley@iee.org>
Date
Jan 29, 2014, 22:21 UTC
Message-ID
<3B29F809B09A46B38D4873721D0CCF06@PhilipOakley>
In-Reply-To
<87eh3q5x42.fsf@fencepost.gnu.org>
From: "David Kastrup" <dak@gnu.org>
Show 26 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> 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.
>

Undefined behaviours become hidden bugs of the future... http://article.gmane.org/gmane.comp.version-control.git/230583

"blog on the problems of unexpected optimization bugs, such as dereferencing a null pointer. "Finding Undefined Behavior Bugs by Finding Dead Code" http://blog.regehr.org/archives/970 which links to the draft of an interesting paper http://pdos.csail.mit.edu/~xi/papers/stack-sosp13.pdf"

The code has now been released http://css.csail.mit.edu/stack/ https://github.com/xiw/stack/, and a few potential errors in Git were caught by that tool by Stefan Beller.

The key point of the paper was never to try to use an 'obvious', but undefined, behaviour.

-- Philip

Previous: David KastrupNext: brian m. carlson
Message 4 of 6 in “C standard compliance?”
  1. David KastrupJan 29, 2014
  2. Junio C HamanoJan 29, 2014
  3. David KastrupJan 29, 2014
  4. Philip OakleyJan 29, 2014
  5. brian m. carlsonJan 29, 2014
  6. David KastrupJan 30, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.