仅在 eclipse "not a structure or union" 中出现此错误
getting this error only in eclipse "not a structure or union"
我只在 eclipse 中遇到这个错误。我的代码 运行 在其他编译器中没有任何错误
这是我在 ECLIPSE 中遇到的错误
21:20:16 **** Incremental Build of configuration Debug for project Sieve of Eratosthenes ****
Info: Internal Builder is used for build
gcc -O0 -g3 -Wall -c -fmessage-length=0 -o "src\Sieve of Eratosthenes.o" "..\src\Sieve of Eratosthenes.c"
..\src\Sieve of Eratosthenes.c: In function 'main':
..\src\Sieve of Eratosthenes.c:16:15: error: request for member 'number' in something not a structure or union
*(pri+(i-2)).number=i;
^
..\src\Sieve of Eratosthenes.c:17:15: error: request for member 'value' in something not a structure or union
*(pri+(i-2)).value =1;
^
..\src\Sieve of Eratosthenes.c:20:23: error: request for member 'number' in something not a structure or union
printf("%d",*(pri+i).number);
^
..\src\Sieve of Eratosthenes.c:21:23: error: request for member 'value' in something not a structure or union
printf("%d",*(pri+i).value);
^
21:20:16 Build Failed. 4 errors, 0 warnings. (took 107ms)
我尝试 运行 我在“https://www.onlinegdb.com/online_c_compiler”中的代码完美运行
#include <stdio.h>
#include <stdlib.h>
struct prime {
int number;
int value;
};
int main() {
int n;
printf("enter range");
scanf("%d",&n);
struct prime pri[n-2];
for(int i=2;i<=n;i++){
pri[i-2].number=i;
pri[i-2].value =1;
}
for(int i=0 ;i<=n-2;i++){
printf("%d ",pri[i].number);
}
}
您遇到的问题与Eclipse无关,而是因为您在不同平台上使用的代码似乎不同。
*(pri+i).number
和
pri[i].number
不一样。
.
具有更高的 precedence,因此它比 *
结合更紧密。
要使第一个版本正常工作:
(*(pri+i)).number
我只在 eclipse 中遇到这个错误。我的代码 运行 在其他编译器中没有任何错误
这是我在 ECLIPSE 中遇到的错误
21:20:16 **** Incremental Build of configuration Debug for project Sieve of Eratosthenes ****
Info: Internal Builder is used for build
gcc -O0 -g3 -Wall -c -fmessage-length=0 -o "src\Sieve of Eratosthenes.o" "..\src\Sieve of Eratosthenes.c"
..\src\Sieve of Eratosthenes.c: In function 'main':
..\src\Sieve of Eratosthenes.c:16:15: error: request for member 'number' in something not a structure or union
*(pri+(i-2)).number=i;
^
..\src\Sieve of Eratosthenes.c:17:15: error: request for member 'value' in something not a structure or union
*(pri+(i-2)).value =1;
^
..\src\Sieve of Eratosthenes.c:20:23: error: request for member 'number' in something not a structure or union
printf("%d",*(pri+i).number);
^
..\src\Sieve of Eratosthenes.c:21:23: error: request for member 'value' in something not a structure or union
printf("%d",*(pri+i).value);
^
21:20:16 Build Failed. 4 errors, 0 warnings. (took 107ms)
我尝试 运行 我在“https://www.onlinegdb.com/online_c_compiler”中的代码完美运行
#include <stdio.h>
#include <stdlib.h>
struct prime {
int number;
int value;
};
int main() {
int n;
printf("enter range");
scanf("%d",&n);
struct prime pri[n-2];
for(int i=2;i<=n;i++){
pri[i-2].number=i;
pri[i-2].value =1;
}
for(int i=0 ;i<=n-2;i++){
printf("%d ",pri[i].number);
}
}
您遇到的问题与Eclipse无关,而是因为您在不同平台上使用的代码似乎不同。
*(pri+i).number
和
pri[i].number
不一样。
.
具有更高的 precedence,因此它比 *
结合更紧密。
要使第一个版本正常工作:
(*(pri+i)).number