Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios xcode LLMV 3.1编译器阵列问题_Ios_Xcode_Compiler Construction - Fatal编程技术网

Ios xcode LLMV 3.1编译器阵列问题

Ios xcode LLMV 3.1编译器阵列问题,ios,xcode,compiler-construction,Ios,Xcode,Compiler Construction,我在Apple LLVM compiler 3.1上遇到了以下问题: int numIndex = 0; int *indices = (int *)malloc(3 * sizeof(int)); indices[numIndex] = numIndex++; indices[numIndex] = numIndex++; indices[numIndex] = numIndex++; for (int i = 0; i < 3; i++) { NSLog(@"%d", indi

我在Apple LLVM compiler 3.1上遇到了以下问题:

int numIndex = 0;
int *indices = (int *)malloc(3 * sizeof(int));
indices[numIndex] = numIndex++;
indices[numIndex] = numIndex++;
indices[numIndex] = numIndex++;
for (int i = 0; i < 3; i++) {
    NSLog(@"%d", indices[i]);
}
int numIndex=0;
int*指数=(int*)malloc(3*sizeof(int));
索引[numIndex]=numIndex++;
索引[numIndex]=numIndex++;
索引[numIndex]=numIndex++;
对于(int i=0;i<3;i++){
NSLog(@“%d”,索引[i]);
}
输出: 101

int numIndex=0;
整数指数[3];
索引[numIndex]=numIndex++;
索引[numIndex]=numIndex++;
索引[numIndex]=numIndex++;
对于(int i=0;i<3;i++){
NSLog(@“%d”,索引[i]);
}
输出: 01


我期望0 1 2作为输出。使用LLVM GCC 4.2的相同代码生成正确的输出。是否有我遗漏的或误解的优化标志?

因此,行为似乎如下所示

int numIndex = 0;
int indices[3];
indices[numIndex] = numIndex++;
这里首先计算右侧,返回0,并将numIndex增加1,然后计算右侧,因此索引[1]得到0

indices[numIndex] = numIndex++;
这里首先计算右侧,返回1,并将numIndex增加1,然后计算右侧,因此索引[2]得到1

indices[numIndex] = numIndex++;
在这里,首先计算右侧,返回2,并将numIndex增加1,然后计算右侧,因此索引[3]得到2(实际上超出范围)

请注意,您从未真正分配过索引[0],因此它可以是任何东西(在我的测试中,它是最大整数)


编辑-从注释中可以看出,这是一种未定义的行为,因此尽管我观察到了这一点,但这不是一个定义的答案

如果Objective C对表达式使用与C相同的规则,您的代码会触发未定义的行为,因此其行为不由语言定义;请参阅以获取解释(
a[i]=i++
是其中的一个示例)。
indices[numIndex] = numIndex++;