Curious About Offbeat "#" Usage in C . . .

Greetings!

Being incredibly rusty in the little C which I ever knew, and, not knowing where else to turn but the best programming community on the web ( :slight_smile: ), I submit the following snippet for a quick question:

#if PERL_VERSION > 7
    if (DEBUG_D_TEST) {
        SV* sva;
        PerlIO_printf(Perl_debug_log, "\n");
        for (sva = PL_sv_arenaroot; sva; sva = (SV*)SvANY(sva)) {
            PerlIO_printf(Perl_debug_log, "sv_arena: 0x%p - 0x%p (%u)\n",
              sva, sva+SvREFCNT(sva), SvREFCNT(sva));
        }
    }
    return perl_destruct( my_perl );
#else
    perl_destruct( my_perl );
    return 0;
#endif

Here's what has me a bit curious about this sample to start: What's with the #if , #else , and #endif ? Surely we're not looking at line commenting here ( :o ).

That being so, what else is going on with the # s in the foregoing context :confused:

Thanks a bunch!

The #if , #else , and #endif are C pre-processor directives. If the macro PERL_VERSION expands to a value greater than 7, the code between the #if and the #else will be compiled into the program; otherwise the code between the #else and the #endif will be compiled into the program.

2 Likes

You are right; those are not comments but they are ignored by C. I believe they are compiler directives.

1 Like

Thanks again for the insights . . .

Geany was ever colorful, but less than helpful :wink: