user361697
user361697

Reputation: 1131

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

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:

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]

Upvotes: 34

Views: 167337

Answers (9)

Surya_Amudha
Surya_Amudha

Reputation: 19

  1. Declare the structs before the main function.
  2. Fix the spelling mistake of that variable name if any e

Upvotes: 0

Claudette Keira
Claudette Keira

Reputation: 9

I solved mine by correcting a simple error in my code. list_t new_end_code declaration brought the error. It should be,

list_t *new_end_code

Upvotes: 0

Vinay Shukla
Vinay Shukla

Reputation: 1844

In this case the user has done mistake in definition and its usage. If someone has done a typedef to a structure the same should be used without using struct following is the example.

typedef struct
{
   int a;
}studyT;

When using in a function

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

Upvotes: 9

Miles C
Miles C

Reputation: 185

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

Upvotes: 18

Abhishek Dave
Abhishek Dave

Reputation: 749

correct typo of

struct xyz a;

to

struct xyx a;

Better you can try typedef, easy to b

Upvotes: 4

ta.speot.is
ta.speot.is

Reputation: 27214

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

Upvotes: 37

Dolan Gish
Dolan Gish

Reputation: 51

you define the struct as xyx but you're trying to create the struct called xyz.

Upvotes: 5

Matthew
Matthew

Reputation: 25763

You define your struct as xyx, however in your main, you use struct xyz a; , which only creates a forward declaration of a differently named struct.

Try using xyx a; instead of that line.

Upvotes: 3

Kerrek SB
Kerrek SB

Reputation: 477040

Say it like this: struct xyx a;

Upvotes: 4

Related Questions