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,976 of 243,242    |
|    Andrey Tarasevich to Michael S    |
|    Re: UB or not UB? was: On Undefined Beha    |
|    12 Jan 26 08:03:31    |
      From: noone@noone.net              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?              Yes, in the same sense as in `foo1`.              > gcc code generator does not think so.              It definitely does. However, since this is the trailing array member of       the struct, GCC does not want to accidentally suppress the classic       "struct hack". It assumes that quite possibly the pointer passed to the       function points to a struct object allocated through the "struct hack"       technique.              Add an extra field after the trailing array and `foo2` will also fold       into `return 1`, just like `foo1`.              Perhaps there's a switch in GCC that would outlaw the classic "struct       hack"... But in any case, it is not prohibited by default for       compatibility with pre-C99 code.              --       Best regards,       Andrey              --- 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