From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bakul Shah To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <75565.1533108087.1@bitblocks.com> Date: Wed, 1 Aug 2018 00:21:27 -0700 Message-Id: <20180801072134.DEB31156E400@mail.bitblocks.com> Subject: [9fans] A compiler bug Topicbox-Message-UUID: d98dff66-ead9-11e9-9d60-3106f5b1d025 Consider: % cat x.c #include uintptr foo[3]; uintptr bar=&foo[2]; % 8c -c x.c # this works. % 5c -c x.c # this fails x.c:3 initializer is not a constant: bar If I change the last line to uintptr* bar=&foo[2]; Both compilers compile it fine. But if I change the last line to uintptr bar=(uintptr)&foo[2]; both compilers fail. Note that the last two examples are type correct. uintptr is the same size as int* so there should be no runtime cost and we already know from the second example that &foo[2] is a link time constant. Similar code to the last two examples compiles on gcc/clang. This seems like a compiler bug.