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

Re: [PATCH 1/9] Define a structure for object IDs.

From
David Kastrup <dak@gnu.org>
Date
May 5, 2014, 09:50 UTC
Message-ID
<87d2fstuzw.fsf@fencepost.gnu.org>
In-Reply-To
<87vbtk60lh.fsf@igel.home>
Andreas Schwab <schwab@linux-m68k.org> writes:
Show 7 quoted lines
> David Kastrup <dak@gnu.org> writes:
>
>> It does not as far as I can see guarantee that a pointer to something
>> of the same type of its first member can be converted to a pointer to
>> a struct even if the struct only contains a member of such type.
>
> This sentence doesn't make any sense.
I disagree.
> If you have an object of struct type

Your premise is _not_ assumed in my statement. My premise was "a pointer to something of the same type of [the struct's] first member". That does quite explicitly _not_ state that an object of struct type is in existence.

> then any pointer to the first member of the object can only be a
> pointer to the one and same object.

The case we are talking about is basically passing a pointer to some actual bonafide toplevel unsigned char [20] object to a routine that expects a pointer to a struct _only_ containing one such unsigned char [20] element.

This is the situation we have to deal with if a caller has not been converted to using such a struct, but the called function does.

More seriously, this is the situation we have to deal with when our SHA1 is actually embedded in some header or whatever else that is actually available only inside of a larger byte buffer.

In that case, the standard does not permit us converting the address where that SHA1 is into a pointer to struct. It may well be that this will fall under the "let's ignore the standard and write for "sensible" compilers/architectures" dictum, but if it doesn't, it might be necessary to first copy the data to a struct before passing it to routines expecting a pointer to struct.

-- 
David Kastrup
Previous: James DenholmNext: Michael Haggerty
Message 12 of 39 in “Use a structure for object IDs.”
  1. 0/9 Use a structure for object IDs.brian m. carlson, May 3, 2014
  2. 1/9 Define a structure for object IDs.brian m. carlson, May 3, 2014
  3. Michael HaggertyMay 4, 2014
  4. Johannes SixtMay 4, 2014
  5. David KastrupMay 4, 2014
  6. Andreas SchwabMay 4, 2014
  7. Johannes SixtMay 4, 2014
  8. Andreas SchwabMay 4, 2014
  9. David KastrupMay 5, 2014
  10. Andreas SchwabMay 5, 2014
  11. James DenholmMay 5, 2014
  12. David KastrupMay 5, 2014
  13. Michael HaggertyMay 5, 2014
  14. Andreas SchwabMay 5, 2014
  15. David KastrupMay 5, 2014
  16. Felipe ContrerasMay 5, 2014
  17. Duy NguyenMay 4, 2014
  18. brian m. carlsonMay 4, 2014
  19. Andreas SchwabMay 4, 2014
  20. David KastrupMay 4, 2014
  21. Andreas SchwabMay 4, 2014
  22. David KastrupMay 4, 2014
  23. Andreas SchwabMay 4, 2014
  24. 2/9 bisect.c: convert to use struct object_idbrian m. carlson, May 3, 2014
  25. 3/9 archive.c: convert to use struct object_idbrian m. carlson, May 3, 2014
  26. 4/9 zip: use GIT_OID_HEXSZ for trailersbrian m. carlson, May 3, 2014
  27. 5/9 branch.c: convert to use struct object_idbrian m. carlson, May 3, 2014
  28. 6/9 bulk-checkin.c: convert to use struct object_idbrian m. carlson, May 3, 2014
  29. 7/9 bundle.c: convert leaf functions to struct object_idbrian m. carlson, May 3, 2014
  30. Michael HaggertyMay 6, 2014
  31. 8/9 cache-tree: convert struct cache_tree to use object_idbrian m. carlson, May 3, 2014
  32. Michael HaggertyMay 6, 2014
  33. Michael HaggertyMay 6, 2014
  34. 9/9 diff: convert struct combine_diff_path to object_idbrian m. carlson, May 3, 2014
  35. Michael HaggertyMay 6, 2014
  36. brian m. carlsonMay 3, 2014
  37. Michael HaggertyMay 4, 2014
  38. Johannes SixtMay 4, 2014
  39. brian m. carlsonMay 4, 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.