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

o4tp2gmn  于 9个月前  发布在  其他
关注(0)|答案(9)|浏览(137)

这是我的C程序

#include <stdio.h>

struct xyx {
    int x;
    int y;
    char c;
    char str[20];
    int arr[2];
};

int main(void)
{
    struct xyz a;
    a.x = 100;
    printf("%d\n", a.x);
    return 0;
}

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

13structtest.c: In function ‘main’:
13structtest.c:13:13: error: storage size of ‘a’ isn’t known
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

#include <stdio.h>

struct xyx {
    int x;
    int y;
    char c;
    char str[20];
    int arr[2];
};

int main(void)
{
    struct xyx a;
    a.x = 100;
    printf("%d\n", a.x);
    return 0;
}

字符串

uttx8gqw

uttx8gqw2#

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

falq053o

falq053o3#

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

typedef struct
{
   int a;
}studyT;

字符串
在函数中使用时

int main()
{
   struct studyT study; // This will give above error.
   studyT stud; // This will eliminate the above error.
   return 0;
}

l2osamch

l2osamch4#

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

qlckcl4x

qlckcl4x5#

像这样说:struct xyx a;

svmlkihl

svmlkihl6#

更正错别字

struct xyz a;

字符串

struct xyx a;


你可以试试typedef,easy to b

rqqzpn5f

rqqzpn5f7#

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

bvuwiixz

bvuwiixz8#

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

list_t *new_end_code

字符串

dbf7pr2w

dbf7pr2w9#

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

相关问题