gcc C -错误:“a”的存储大小未知

o4tp2gmn  于 2024-01-08  发布在  其他
关注(0)|答案(9)|浏览(223)

这是我的C程序

  1. #include <stdio.h>
  2. struct xyx {
  3. int x;
  4. int y;
  5. char c;
  6. char str[20];
  7. int arr[2];
  8. };
  9. int main(void)
  10. {
  11. struct xyz a;
  12. a.x = 100;
  13. printf("%d\n", a.x);
  14. return 0;
  15. }

字符串
这是我得到的错误....
按ENTER键或键入命令继续

  1. 13structtest.c: In function main’:
  2. 13structtest.c:13:13: error: storage size of a isnt known
  3. 13structtest.c:13:13: warning: unused variable a [-Wunused-variable]

w46czmvw

w46czmvw1#

您的结构体名为struct xyx,但a的类型为struct xyz.Once you fix that, the output is 100

  1. #include <stdio.h>
  2. struct xyx {
  3. int x;
  4. int y;
  5. char c;
  6. char str[20];
  7. int arr[2];
  8. };
  9. int main(void)
  10. {
  11. struct xyx a;
  12. a.x = 100;
  13. printf("%d\n", a.x);
  14. return 0;
  15. }

字符串

展开查看全部
uttx8gqw

uttx8gqw2#

对于任何有这个问题的人来说,这是一个打字错误。检查你的结构delcerations和结构的拼写

falq053o

falq053o3#

在这种情况下,用户在定义和用法上犯了错误。如果有人对结构做了typedef,那么应该使用相同的结构,而不使用struct,下面是示例。

  1. typedef struct
  2. {
  3. int a;
  4. }studyT;

字符串
在函数中使用时

  1. int main()
  2. {
  3. struct studyT study; // This will give above error.
  4. studyT stud; // This will eliminate the above error.
  5. return 0;
  6. }

展开查看全部
l2osamch

l2osamch4#

你把结构体定义为xyx,但你试图创建一个名为xyz的结构体。

qlckcl4x

qlckcl4x5#

像这样说:struct xyx a;

svmlkihl

svmlkihl6#

更正错别字

  1. struct xyz a;

字符串

  1. struct xyx a;


你可以试试typedef,easy to b

rqqzpn5f

rqqzpn5f7#

你将结构体定义为xyx,但是在main中,你使用了struct xyz a;,这只会创建一个不同命名的结构体的前向声明。
尝试使用xyx a;而不是这一行。

bvuwiixz

bvuwiixz8#

我通过纠正代码中的一个简单错误解决了我的问题。list_t new_end_code声明带来了错误。它应该是,

  1. list_t *new_end_code

字符串

dbf7pr2w

dbf7pr2w9#

1.在main函数之前解构结构体。
1.如果变量名有拼写错误,

相关问题