1

sorry for this newbie question but I don't find any good resource on web to explain what this means:

struct {
  struct spinlock lock;
  struct proc proc[NPROC]; //NPROC = 64
} ptable;

I see the resources over the web and find these types of define a struct:

//first method
struct Foo { ... };

//second method
typedef struct Foo { ... } Foo;
mojibuntu
  • 307
  • 3
  • 16

2 Answers2

2
struct foo { ... };

The struct tag (foo here) is optional. If it's omitted like in your example, you can use the variable ptable which is of this type, but you can't define other variables of this type later.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
1
struct 
{
  struct spinlock lock;
  struct proc proc[NPROC]; //NPROC = 64
}
ptable;

This defines a nameless struct and at the same time declares a variable named ptable

As pointed by Yu Hao, you can't define variables of this struct type later. You can make as many variables at the time you define the nameless struct

struct 
{
   /* your variables*/
} a,b[2] ;

as opposed to a named struct,

struct my_struct
{
   /* your variables*/
} a,b[2] ;

and you can define variables later as struct my_struct c

Community
  • 1
  • 1
Suvarna Pattayil
  • 5,136
  • 5
  • 32
  • 59