From: already5chosen@yahoo.com   
      
   On Mon, 12 Jan 2026 20:35:09 -0500   
   "James Russell Kuyper Jr." wrote:   
      
   > On 12/01/2026 14:28, Michael S wrote:   
   > > On Thu, 1 Jan 2026 22:54:05 +0100   
   >   
   > > On related note.   
   > >   
   > >   
   > > struct bar1 {   
   > > int table[4];   
   > > int other_table[4];   
   > > };   
   > >   
   > > struct bar2 {   
   > > int other_table[4];   
   > > int table[4];   
   > > };   
   > >   
   > > int foo1(struct bar1* p, int v)   
   > > {   
   > > for (int i = 0; i <= 4; ++i)   
   > > if (p->table[i] == v)   
   > > return 1;   
   > > return 0;   
   > > }   
   > >   
   > >   
   > > int foo2(struct bar2* p, int v)   
   > > {   
   > > for (int i = 0; i <= 4; ++i)   
   > > if (p->table[i] == v)   
   > > return 1;   
   > > return 0;   
   > > }   
   > >   
   > > According to C Standard, access to p->table[4] in foo1() is UB.   
   > > [O.T.]   
   > > I want to use language (or, better, standardize dialect of C) in   
   > > which behavior in this case is defined, but I am bad at influencing   
   > > other people. So can not get what I want.   
   >   
   > OK - so how do you want it to be defined? I've used languages where   
   > table[n] for n>3 would have exactly the same effect as table[3], and   
   > table[n] for n<0 would have exactly the same effect as table[0]. I've   
   > seen algorithms that were actually simplified by relying upon this   
   > behavior.   
      
   I want "my" dialect to be based on abstract machine with flat memory   
   model. All variables, except for automatic variables which address   
   was never taken by the program, are laid upon one big implicit   
   array of char.   
   For my purposes, Harvard abstract machine is sufficient.   
   I am sure that there are multiple people that would want option for Von   
   Neumann abstract machine, i.e. for program code to be laid over the same   
   implicit array as variables, with as many things defined in the   
   standard as practically possible. My aspirations do not go that far.   
      
   In specific case of 'struct bar1', it means that I want p->table[4:7] to   
   be absolute equivalents of p->other_table[0:3]. For p->table[n] where n   
   < 0 or n > 7, I want generated code to access respective locations in   
   implicit underlying array. Whether resulting behavior defined or   
   undefined would depend on the specifics of the caller.   
      
   If you say that "my" dialect is less optimizable than Standard C then   
   my answer is "Yes, I know and I don't care".   
      
   If you say that "my" dialect removes certain potential for detection of   
   buffer overflows by compiler then my answer is "Generally, yes, and it's   
   not great, but I consider it a fair price.". Pay attention that there   
   are still plenty of places where compiler can warn, like in majority of   
   automatic and static arrays. In other situations bound checking can be   
   enabled at spot by special attribute.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|