Ildar Asked:2022-06-22 00:47:51 +0000 UTC2022-06-22 00:47:51 +0000 UTC 2022-06-22 00:47:51 +0000 UTC 这样的指令在 C++ 中意味着什么? 772 int main() { int a[10] = { [0 ... 5] = 1,[6 ... 9] = 2 }; return 0; } 0在MacOS, 编译器LLVM Clang, IDE上编译并返回代码Xcode c++ 1 个回答 Voted Best Answer AlexGlebe 2022-06-22T02:41:55Z2022-06-22T02:41:55Z 编译器实现了非标准功能。标准禁止。 警告:ISO C 禁止指定要初始化的元素范围 [-Wpedantic] 这(带索引的元素初始化)仅在 C 中是可能的。还没有加入专业版。 数组集.c: int main() { // здесь предупреждение int a[10] = { [0 ... 5] = 1,[6 ... 9] = 2 }; // здесь чистый код без ошибок int b[10] = { [0] = 1 ,[1]=1,[2]=1,[3]=1,[4]=1,[5] = 1, [6]=2,[7]=2,[8]=2,[9] = 2 }; return 0; } 数组集.s: .file "arrayset.c" .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl $1, -48(%rbp) movl $1, -44(%rbp) movl $1, -40(%rbp) movl $1, -36(%rbp) movl $1, -32(%rbp) movl $1, -28(%rbp) movl $2, -24(%rbp) movl $2, -20(%rbp) movl $2, -16(%rbp) movl $2, -12(%rbp) movl $1, -96(%rbp) movl $1, -92(%rbp) movl $1, -88(%rbp) movl $1, -84(%rbp) movl $1, -80(%rbp) movl $1, -76(%rbp) movl $2, -72(%rbp) movl $2, -68(%rbp) movl $2, -64(%rbp) movl $2, -60(%rbp) movl $0, %eax popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size main, .-main .ident "GCC: (SUSE Linux) 7.5.0" .section .note.GNU-stack,"",@progbits
编译器实现了非标准功能。标准禁止。
这(带索引的元素初始化)仅在 C 中是可能的。还没有加入专业版。
数组集.c:
数组集.s: