A connection has recently appeared with a mixed literal, and, as I understand it, it is more correct to use it. Fortunately, it works with both gcc and clang on ubuntu.
int main() {
int *p = (int []) {1, 2};
return 0;
}
However, I notice another way to use the composite literal shown below. It's a bit strange; it's just an array initializer. The following code is compiled using a clang, but not with the gcc, array initialized from non-constant array expression.
int main() {
int p[] = (int []) {1, 2};
return 0;
}
Is it intentional or what?
ENV:
- gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
- Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)
CMD:
source
share