user145959 user145959 - 11 months ago 85
C Question

What does this function input means in C language: MODELDIR "/en-us/en-us"

I read the following code from the PocketSphinx tutorial

config = cmd_ln_init(NULL, ps_args(), TRUE,
"-hmm", MODELDIR "/en-us/en-us",
"-lm", MODELDIR "/en-us/en-us.lm.bin",
"-dict", MODELDIR "/en-us/cmudict-en-us.dict",
NULL);


It's first time I see a variable--
MODELDIR
--beside a string--
"/en-us/en-us"
. How is this possible? I've never seen anything like this in C/C++ tutorial books!

If I want to search for more information about this, what keywords should I use for search?

Answer Source

MODELDIR is a macro expanding to a string. C joins adjacent strings into single ones*, so if MODELDIR would be #defined to "/foo/bar", this would result in the following function call:

config = cmd_ln_init(NULL, ps_args(), TRUE,
             "-hmm", "/foo/bar/en-us/en-us",
                 "-lm", "/foo/bar/en-us/en-us.lm.bin",
                 "-dict", "/foo/bar/en-us/cmudict-en-us.dict",
                 NULL);

*) So, writing

"Hello, " "World!"

is exactly the same as

"Hello, World!"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download