4

header file cissvar.h has this definition:

#define CISSQ_REQUEST_QUEUE(name, index)                                \
static __inline void                                                    \
ciss_initq_ ## name (struct ciss_softc *sc)                             \
{                                                                       \
    STAILQ_INIT(&sc->ciss_ ## name);                                    \
    CISSQ_INIT(sc, index);                                              \
}                                                                       \
(...)

And actual usage in ciss.c looks like this:

ciss_initq_free(sc);
ciss_initq_notify(sc);

It would be great if someone can explain how does this work.

So,

  1. name refers to either "free" or "notify"
  2. where does "index" come from?
  3. how does compiler do the magic binding between .h and .c here?
wovano
  • 4,543
  • 5
  • 22
  • 49
hari
  • 9,439
  • 27
  • 76
  • 110
  • Run it through the preprocessor and you will see ... – alk Apr 08 '13 at 17:24
  • possible duplicate of [Double hash before parameter in function call](http://stackoverflow.com/questions/7880058/double-hash-before-parameter-in-function-call) or [code-what-does-double-hash-means](http://stackoverflow.com/questions/653466/reading-zend-engine-api-code-what-does-double-hash-means) – Mike Apr 08 '13 at 17:26
  • An *actual usage* would need to look like `CISSQ_REQUEST_QUEUE(name,idx)` and would create a function incorporating `name` and `idx`. The `##`` symbol is the preprocessor's token pasting operator, which basically takes static text and/or macro parameters and combines them into a single string for the compiler to use later. – Steve Valliere Apr 08 '13 at 17:27

2 Answers2

6

The important lines are these (also in cissvar.h):

CISSQ_REQUEST_QUEUE(free, CISSQ_FREE);
CISSQ_REQUEST_QUEUE(notify, CISSQ_NOTIFY);

They invoke that macro that you pasted. The "##" operator concatenates two words of code together into a single word, so the code generated (with the macro expansion) for the first line looks something like this:

static __inline void                                                    
ciss_initq_free(struct ciss_softc *sc)                             
{                                                                       
    STAILQ_INIT(&sc->ciss_free);                                    
    CISSQ_INIT(sc, CISSQ_FREE);                                              
}
DigitalGhost
  • 773
  • 1
  • 5
  • 14
5

## makes the preprocessor concatenate the two arguments to the ## operator.

alk
  • 69,737
  • 10
  • 105
  • 255