Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C: struct declaration with function. Storage size isn't known

Tags:

c

function

struct

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?

like image 551
I159 Avatar asked Feb 17 '23 10:02

I159


1 Answers

You forgot to include:

   #include <sys/types.h>
   #include <sys/stat.h>
like image 60
xtof pernod Avatar answered May 09 '23 07:05

xtof pernod