home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 242,843 of 243,242   
   Kaz Kylheku to highcrew   
   Re: UB-free slice   
   06 Jan 26 20:48:51   
   
   From: 046-301-5902@kylheku.com   
      
   On 2026-01-05, highcrew  wrote:   
   > In my understanding, if we call buffer_append(&x, &y) for x.bytes and   
   > y.bytes pointing to overlapping areas of the same array, we get UB by   
   > the first two parameters of memcpy being restrict-qualified pointers.   
      
   Nope! The standard doesn't provide a /definition/ of memcpy.   
      
   And restrict qualifiers on pointer parameters in a /declaration/ don't   
   mean anything (and need not be repeated in the definition).   
      
   memcpy is not required to take overlapping objects for the   
   reason that its description says so.   
      
   That situation existed long before there was a restrict, and has   
   implications in the absence of restrict. Various ways of implemeting a   
   memcpy-like function will produce various unexpected results when   
   objects overlap, even without any undefined  behavior taking place. For   
   instance if we copy byte-by-byte, from lowest address to highest, then   
   we end up writing into memory that our loop is about to read from,   
   corrupting the data.   
      
   In order not to place any restrictions on how a memcpy may be   
   implemented, whether  with the help of restrict pointers, or assembly   
   language or whatever else, the standard makes overlapping inputs   
   undefined.   
      
   --   
   TXR Programming Language: http://nongnu.org/txr   
   Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal   
   Mastodon: @Kazinator@mstdn.ca   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca