C: struct declaration with function. Storage size isn't known
11,295
You forgot to include:
#include <sys/types.h>
#include <sys/stat.h>
Author by
I159
Updated on July 11, 2022Comments
-
I159 almost 2 years
My question about using functions with
struct
. I took the snippet from R.Stevens' book and I saw similar snippets a couple of time. I suggest to get some C and Linux experience, but I really do not know how to use struct in right way in this case.struct stat buf; // The error line for (i=1; i < argc; i++){ if (lstat(argv[i], &buf) < 0) { // Usage of err_ret("lstat error"); continue; } if (S_ISERG(buf.st_mode)) ptr = "regular";
When I compile my code I have got an error:
type.c: In function ‘main’: type.c:9:15: error: storage size of ‘buf’ isn’t known
What is wrong with the struct declaration? Should I explicitly declare struct size? If it is, how do I know it? And the main question - how is it works
struct method name
? -
I159 almost 11 yearsYes, I forgot to include all of them! I will read about these libraries. Thanks!
-
xtof pernod almost 11 yearsYou're welcome; but technically these are not library, but include files, that describe the
*stat()
functions, which are in the standard C library..