Reputation: 1131
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
Reputation: 19
Upvotes: 0
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
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
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
Reputation: 749
correct typo of
struct xyz a;
to
struct xyx a;
Better you can try typedef, easy to b
Upvotes: 4
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
Reputation: 51
you define the struct as xyx but you're trying to create the struct called xyz.
Upvotes: 5
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