int constexpr foo[1] = { 4 }; static int j = *foo;

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Given the following code:

int main() {
    int constexpr foo[1] = { 4 };
    static int i = foo[0];
    static int j = *foo;
}

gcc14 -std=c23 gives:

x.c: In function 'main':
x.c:4:20: error: initializer element is not constant
    4 |     static int j = *foo;
      |                    ^

Why is the line above okay, but this one is an error?

C23 6.5.3.2p2 says "The definition of the subscript operator [] is that E1[E2] is identical
to (*((E1)+(E2)))."

This would suggest that foo[0] is identical to *(foo+0) is identical to *foo?





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux