#include<stdio.h>
struct s_{
int b;
}s;
int func1(s** ss){
*ss->a = 10;
}
int func(s* t){
func1(&t);
}
int main(){
s a;
func(&a);
printf("\n a : %d \n",a.b);
return 0;
}
尝试使用示例程序并使用o / p获取错误。
O / P:
[root@rss]# gcc d.c
d.c:6: error: expected ‘)’ before ‘*’ token
d.c:9: error: expected ‘)’ before ‘*’ token
d.c: In function ‘main’:
d.c:13: error: expected ‘;’ before ‘a’
d.c:14: error: ‘a’ undeclared (first use in this function)
d.c:14: error: (Each undeclared identifier is reported only once
d.c:14: error: for each function it appears in.)
答案 0 :(得分:6)
typedef
所需的s
。b
而不是a
。ss
func1
main
周围的parens。C
中无参数int main(void)
为#include <stdio.h>
typedef struct s_{
int b;
}s;
void func1(s** ss){
(*ss)->b = 10;
}
void func(s* t){
func1(&t);
}
int main(void)
{
s a;
func(&a);
printf("\n a.b : %d \n", a.b);
return 0;
}
。
{{1}}
答案 1 :(得分:3)
查看代码后,很明显您在typedef
struct
关键字
struct s_{
int b;
}s;
应该是
typedef struct s_{
int b;
}s;
和
*ss->a = 10; //wrong. operator precedence problem
// `->` operator have higher precedence than `*`
没有会员名称a
。它应该是
(*ss)->b = 10;
答案 2 :(得分:1)
如图所示s
是struct s_
类型的对象。您不能将其用作函数原型中的类型。您是否要使用typedef
引入类型别名?