xzhu
xzhu

Reputation: 5755

What does "CONST func(arg);" mean in C language?

This is a c program demonstrating some basic usage of the libxml2 library. Below is quoted from the main function:

LIBXML_TEST_VERSION example1Func(argv[1]);

What does this statement stand for?

I can only tell that LIBXML_TEST_VERSION is obviously a constant, and after that is a function call, that function returns nothing (void). But I've no idea what it means the statement in whole.

Upvotes: 2

Views: 457

Answers (3)

NPE
NPE

Reputation: 500257

It is the standard convention to name C preprocessor macros in ALL_UPPERCASE. As you suggest, this is often used for compile-time constants. However, there are other uses.

Now to your example. The original source looks like this (comments are mine):

LIBXML_TEST_VERSION    /* line 1 */
example1Func(argv[1]); /* line 2 */

The first line is a C macro. The second line is a function call. The two are not part of the same statement as your question implies. It is unfortunate that the way LIBXML_TEST_VERSION is defined it does not require a semicolon at the end; if this were the case, there would be no confusion around whether the two lines are part of the same statement.

In case you're wondering what exactly is LIBXML_TEST_VERSION:

Macro: LIBXML_TEST_VERSION

#define LIBXML_TEST_VERSION
Macro to check that the libxml version in use is compatible
with the version the software has been compiled against

Upvotes: 2

Paul R
Paul R

Reputation: 212949

LIBXML_TEST_VERSION is not a constant - it's a macro - see the documentation here:

Macro: LIBXML_TEST_VERSION

#define LIBXML_TEST_VERSION
Macro to check that the libxml version in use is compatible with the version the software has been compiled against

It's also nothing to do with the call to example1func() - the code should look like this (comments are mine):

LIBXML_TEST_VERSION    // test libxml version

example1func();        // call example1func

Upvotes: 4

Greg Hewgill
Greg Hewgill

Reputation: 992857

It appears as though LIBXML_TEST_VERSION is a macro that expands to one or more statements. From Google code search, it appears the definition is something like:

#define LIBXML_TEST_VERSION xmlCheckVersion(20703);

where 20703 is whatever version you're compiling against.

This statement is independent from the call to example1Func().

Upvotes: 2

Related Questions