2

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.

3
  • I feel terribly sorry now because the line from the original program I've linked to is actually two lines. I guess it's my IDE's auto indent system made the wrong decision. So this question is actually meaningless.
    – xzhu
    May 17, 2011 at 8:30
  • Still, you guys are impressively fast!
    – xzhu
    May 17, 2011 at 8:32
  • No problem - today we all learned that: all uppercase symbols are not necessarily constants, that you should not trust the formatting of code, and what the LIBXML_TEST_VERSION macro does. ;-)
    – Paul R
    May 17, 2011 at 8:36

3 Answers 3

4

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
2
  • 5
    +1: This kind of macro is irritating, though, for exactly this sort of confusion. I would prefer it if the macro didn't define the trailing ;, which would at least force you to explicitly suffix the instantation with a ;, thus reducing visual confusion. May 17, 2011 at 8:25
  • 2
    @Oli: indeed - typically multi-line macros should be wrapped in do { ... } while (0) to allow for a terminating semicolon
    – Paul R
    May 17, 2011 at 8:27
2

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().

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.