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 243,007 of 243,242   
   James Russell Kuyper Jr. to Michael S   
   Re: UB or not UB? was: On Undefined Beha   
   13 Jan 26 22:20:03   
   
   From: jameskuyper@alumni.caltech.edu   
      
   On 2026-01-12 12:36, Michael S wrote:   
   > On Mon, 12 Jan 2026 08:03:31 -0800   
   > Andrey Tarasevich  wrote:   
   >   
   >> On Mon 1/12/2026 6:28 AM, Michael S wrote:   
   >>>   
   >>> According to C Standard, access to p->table[4] in foo1() is UB.   
   >>> ...   
   >>> Now the question.   
   >>> What The Standard says about foo2() ? Is there UB in foo2() as   
   >>> well?   
   ...   
   >>> gcc code generator does not think so.   
      
   When the behavior is undefined, there's no such thing as incorrect   
   generated code. In particular, undefined behavior includes the   
   possibility of your code producing precisely the same behavior that you   
   incorrectly thought it was required to have.   
      
   > Do you have citation from the Standard?   
      
   table[4] is defined as equivalent to *(table+4), and and the relevant   
   rule for that expression is "If the addition or subtraction produces   
   an overflow, the behavior is undefined." (6.5.7p9)   
      
   ...   
   > But I was interested in the "opinion" of C Standard rather than of gcc   
   > compiler.   
   > Is it full nasal UB or merely "implementation-defined behavior"?   
      
   UB.   
      
   --- 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