This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

what's thie meaning for "#ifndef __C51__"

In Keil demos, I find some definitions such as "#ifndef __C51__", what's the meaning for double '_'.

Parents Reply Children
  • Standard Pascal does not allow for separate compilation at all, so the issue of modules and name spaces does not arise. Real-world useful Pascal implementations (say, Borland's Turbo Pascal) added their own language mechanisms to support separate compilation, none of which are necessarily compatible. So it's hard to say anything meaningful about what "Pascal" does with namespaces.

    I favor the practice of using a .h file as a "declarations" file only. Put in the internal #include guards. Some compilers will track the #include nesting and avoid re-including a file anyway, but it's best to be sure. Putting in the actual definitions (space-reserving, as opposed to extern references) tends to lead to trouble.

    There are occasional other header file tricks, usually redefining a macro in two different ways to produce two different bits of C syntax when included from different contexts. (See, for example, Bob Horeck's comment and use of TxtItem in the thread http://www.keil.com/forum/docs/thread2785.asp. The authors of the OSE RTOS are also fond of this trick for implementing their configuration files.) This sort of thing is, in my opinion, best kept well separated from your "normal" header files to avoid confusion.

    There's use of the #include mechanism to emulate module export / linkage mechanisms that ought to have been built into the language proper, which is a near-universal C programmer convention; and then there's use of the preprocessor just as a text macro processor not necessarily having anything to do with C.