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,985 of 243,242   
   James Russell Kuyper Jr. to Michael S   
   Re: UB or not UB? was: On Undefined Beha   
   12 Jan 26 20:35:09   
   
   From: jameskuyper@alumni.caltech.edu   
      
   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.   
      
   --- 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