<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/120357>120357</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Old alignof Macro for C89 Broken as C23 Extension
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Sha0
      </td>
    </tr>
</table>

<pre>
    Please consider the following **offsetof.c** file:

```
~ $ cat offsetof.c 
/*
 * Compiler:

~ $ gcc -v
clang version 19.1.4
Target: aarch64-unknown-linux-android24
Thread model: posix
InstalledDir: /data/data/com.termux/files/usr/bin

 * Error:

 ~ $ gcc -ansi -pedantic -Wall -Wextra -Werror -o offsetof offsetof.c 2>&1
offsetof.c:27:21: error: defining a type within 'offsetof' is a C23 extension [-Werror,-Wc23-extensions]
   27 |     return offsetof(struct { char c; }, c);
      | ^~~~~~
/data/data/com.termux/files/usr/lib/clang/19/include/__stddef_offsetof.h:16:43: note: expanded from macro 'offsetof'
   16 | #define offsetof(t, d) __builtin_offsetof(t, d)
      | ^
1 error generated.

 * Why?
 */
#include <stddef.h>

int main(void)
  {
    return offsetof(struct { char c; }, c);
  }
```

A relevant portion of C89 for **stddef.h** is:

```
[...] and

 offsetof( type,  member-designator)

which expands to an integral constant expression that has type size_t,
the value of which is the offset in bytes, to the structure member
(designated by member-designator ), from the beginning of its
structure (designated by type ). The member-designator shall be such
that given

         static  type t;

then the expression &(t.  member-designator ) evaluates to an address
constant.  (If the specified member is a bit-field, the behavior is
undefined.)
[...]
```

The **clang** error-message reports a "C23 extension."  It is now December, 2024.  At least 12 years ago, this "code-snippet" was produced:
- https://ideone.com/wL6wm
- (linked to from the https://www.iso-9899.info/wiki/Code_snippets page)

It uses an **alignof** macro shared by Mr. Chris M. Thomasson in **Usenet** (probably the **comp.lang.c** section) from before that time, which is something like:
```
#define alignof(type) (offsetof(struct {char c; type t;}, t))
```

I suspect that similar macros have been in use for much, much longer, but I could be mistaken.

If we are invoking clang in a C89 mode and we interpret the quotation above as authoritative, then I perceive that the type used within the offsetof macro in the code-file (shared far above) meets the "static type t;" condition and I do not perceive a C23 extension being relevant to such old usage.

Is this an opportunity for improvement?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVkFv47wR_TXMZSBBouzYOvigOGsgQBct0K_YY0CJI4kNRaokZSc9fL-9GFK2s7s5FJ8QRLCkGb558-aRwns1GMQD2z6x7fODWMJo3eGfoygeWis_Dv_QKDxCZ41XEh2EEaG3WtuLMgMw3jDe2L73GGyfd-k39EojqxpWxL_HYv0rmj-B8Q10IsA9BugbfqLQoqGMcLTTrDS6W4oUNnQdZGdWNJ0WZoAzOq-sgbLOy3zDiuYP4QYMrGpACNeNj5tsMW_GXkymlVneM2Gks0ry-O3oUEiYrERNEbP16p0VzYvxQWiN8lnR8sD4SYog7rfOTnlANy3vjJ-oTs_4afGO8VOrTIIbi_jmnL1XAJ9KEMYryGaUwgTVQfZDaA3ZD3wPTtCdAiGzN4o-c8VZ9Y3xx5IVn1mvGr6jfyVBxnVhkNgrQ10SED5mhIsKozLA-O4ayvgOlAcBR14Bvgc0kVG2fVphMH7MfnS8ym4vPds-Uz0AfAdsdwS6HIbFGbin3fvgli4A2z1BNwoHHauegO2eGT9Cx3jNqqeUBSBmYdtvf9KVtPB_U65VSx-QHhg_lTXjJ2U6vUhk_PT66oOU2L_emBpZ1ZSPrGo2FRFkbMDI2PssjEQJvbMTTKJz9heWEtbyMWHlVaQWPxccqDLJeA2vr-2idFDm9avXv1bNiqZMLYMBDToRUOafZPRj_GDVaf1FY0IEVWuRwKpjqpFK-5bClAkwCWUY35-tuq3JdlfG_3q36NHPA82KpgGHGs_CBJitCyQg28NxX0Nv3eoQN5DJH5T_0h3Y9inPc7Z9BmHkysEnlFHFBAkmnFp0mUQyLxFIp3X6_jKqblwb6iFYEAaUCTg4oaOJB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