What does this code do?

C

cman

I found this macro in the Linux source, can anyone help me decipher
what it is doing?

#define LIST_HEAD_INIT(name) { &(name), &(name) }

cman
 
R

Richard Bos

cman said:
I found this macro in the Linux source, can anyone help me decipher
what it is doing?

#define LIST_HEAD_INIT(name) { &(name), &(name) }

Nothing, /per se/. How is it called?

Richard
 
R

Richard Bos

cman said:
It is called as LIST_HEAD_INIT(inode_used) - where inode_used is of
type struct inode etc.

A single object? No side effects? Not as part of another line? Then it
does exactly nothing.

Richard
 
U

user923005

I found this macro in the Linux source, can anyone help me decipher
what it is doing?

#define LIST_HEAD_INIT(name) { &(name), &(name) }

Many compilers will show you the result of the preprocessor output if
you choose a compiler flag to allow it.
For instance, with MS VC++ it is /EP and with gcc, you can run the
preprocessor on its own.
 
M

mark_bluemel

A single object? No side effects? Not as part of another line? Then it
does exactly nothing.

The OP seems not to have done enough research...
Here's an example:-
struct address_space swapper_space = {
- .page_tree = RADIX_TREE_INIT(GFP_ATOMIC),
- .page_lock = RW_LOCK_UNLOCKED,
- .clean_pages = LIST_HEAD_INIT(swapper_space.clean_pages),
- .dirty_pages = LIST_HEAD_INIT(swapper_space.dirty_pages),
- .io_pages = LIST_HEAD_INIT(swapper_space.io_pages),
- .locked_pages = LIST_HEAD_INIT(swapper_space.locked_pages),
[etc...]

It looks to me to be an initializer for a circular list.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top