kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

6_5_2_1_01_subscript_conditional_zero_branch.c (711B)


      1 /* ยง6.5.2.1 -- E1[E2] requires one pointer-to-object and one integer
      2  * operand. When E2 is a conditional expression whose two arms are an
      3  * integer constant `0` and a non-constant integer, kit (after the
      4  * usual arithmetic conversions on `?:`) appears to treat the constant
      5  * `0` arm as a null-pointer-constant, unifies the `?:` result as a
      6  * pointer, then rejects `ptr[ptr]`. Hits lua-5.4.7 lstrlib.c at
      7  *   buff[islittle ? 0 : size - 1] = ...
      8  * which the diagnostic flags as "invalid subscript: needs one pointer
      9  * and one integer". */
     10 int test_main(void) {
     11   char buff[4] = {0};
     12   int islittle = 1;
     13   int size = 4;
     14   buff[islittle ? 0 : size - 1] = 42; /* writes buff[0] = 42 */
     15   return buff[0];
     16 }