Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C - error: storage size of ‘a’ isn’t known

Tags:

c

gcc

struct

This is my C program...

#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;
}

This is the error that I am getting....

Press ENTER or type command to continue

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]
like image 390
user361697 Avatar asked Jan 10 '12 05:01

user361697


2 Answers

Your struct is called struct xyx but a is of type 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;
}
like image 178
ta.speot.is Avatar answered Oct 13 '22 21:10

ta.speot.is


To anyone with who is having this problem, its a typo error. Check your spelling of your struct delcerations and your struct

like image 14
Miles C Avatar answered Oct 13 '22 20:10

Miles C