kit

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

attr_p2_08_weak_undef.c (603B)


      1 /* Phase 2: an undefined weak symbol resolves to 0 at link time without
      2  * an "undefined reference" error. Phase 1 records the attribute but
      3  * doesn't honor it, so the link step fails with an unresolved symbol.
      4  *
      5  * The well-defined operation on a weak undef is taking its address —
      6  * &sym is 0 when the linker can't resolve it. Dereferencing the
      7  * resulting NULL is UB (matches GCC/Clang: they emit a plain load and
      8  * trust the programmer to guard), so this test checks the address. */
      9 extern int weak_missing __attribute__((weak));
     10 
     11 int test_main(void) { return (&weak_missing != 0) ? 1 : 0; }