Hello Thomas,
Can I comment bigger code-chunks with #if and #if def?
That would be #ifdef/#ifndef/#if defined/#if !defined ... #endif,
but in principle: Yes.
I read this - a (simple;-)) sample would be great.
#define COMMENT_TEST
int main (void)
{
....
#ifndef COMMENT_TEST
/* Code with many comments */
....
#endif
....
return 0;
}
the #if... preprocessor directives are used for conditional
compilation, so you say: If COMMENT_TEST is not defined, keep
this code; otherwise everything between #ifndef and #endif
is not "seen" by the compiler.
You have, however, another problem:
If there are already #if... directives in your code, you can
unintentionally get errors:
/*
#define COMMENT_TEST
*/
#include <stdio.h>
int main (void)
{
puts("NCT");
#ifndef COMMENT_TEST
/* Code with many comments */
puts("CT");
#ifdef SPECIAL_CASE
puts("SC");
#else
puts("NSC");
#endif /* !defined COMMENT_TEST */
puts("NSC");
puts("NCT");
#endif /* SPECIAL_CASE */
puts("NCT");
return 0;
}
Now, #endif /* !defined COMMENT_TEST */ is the nearest #endif
to #ifdef SPECIAL_CASE, so it belongs to that if; that is, we would
expect that for SPECIAL_CASE, we get an "SC" output line, but
in truth we get "SC" and "NSC" which is not what we intended
(from the comments at least).
If you are using C99, I would recommend using an editor which
can comment selected lines with // line comments and can get
rid of the first line comments of a line in a selected region.
Cheers
Michael