Jump to content

how does following structure gets expanded to

- - - - -

  • Please log in to reply
3 replies to this topic

#1
onus

onus

    Programmer

  • Members
  • PipPipPipPip
  • 115 posts
On this link
Linux/drivers/parport/parport_pc.c - Linux Cross Reference - Free Electrons
they defined a structure superio_struct and initialized as
superios[NR_SUPERIOS] = { {0,},};
I am not able to understand above initialization has what is it getting initialized to.

What I deduce till now is superios is a structure array of struct superio_struct
and NR_SUPERIOS is defined as 3 hence an array of structure of size 3
but
superios[0]=??

superios[1]=??

superios[2]=??

This part is not clear to me as to what these individual members are initialized to.

#2
mnirahd

mnirahd

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 330 posts
Hi,

Look at the definition of the identifier


 #define NR_SUPERIOS 3

 static struct superio_struct {  /* For Super-IO chips autodetection */

        int io;

        int irq;

        int dma;

} superios[NR_SUPERIOS] = { {0,},};




The above definition does the following

1. Declares a structured named superio_struct & declares array of that structure of size 3
2. The initialization array that all of the elements in structure array are initialized to 0.

So they are initialized as similarly as following,


superios[0]={0, 0 , 0};

superios[1]={0, 0 , 0};


superios[2]={0, 0 , 0};




I hope that it helps

Munir

#3
onus

onus

    Programmer

  • Members
  • PipPipPipPip
  • 115 posts
No I could not understand how is that getting initialized to zero.

#4
mnirahd

mnirahd

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 330 posts
Hi


superios[NR_SUPERIOS] = { {0,},};


This way declaring the array to size of 3, and initializing the first element in following way
superios[0].io = 0;

Now look at


superios[NR_SUPERIOS] = { {2,},};


this initializes the first element of the array to 2 like



superios[0].io = 2;


rest of the part of the array is being initialized to 0.

Munir




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users