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
  • "I don't know the difference between definition and declaration"

    Read K&R, and see this thread:
    http://www.keil.com/forum/docs/thread1847.asp

    Basically, a definition creates code and/or data; a declaration merely informs the compiler about code and/or data.

    Therefore, declarations are good in headers; definitions are bad!

    "compiler does not allow me to declare a variable in H file"

    Nonsense!
    The compiler doesn't care - it will let you have both definitions and declarations in headers.

    If you get errors when you declare (or, more likely, define) a variable in a Header file, it has nothing to do with the fact that it's in a header file per se; more likely you are falling into one of the pitfalls which is why we say: don't define code or data in headers!

Reply
  • "I don't know the difference between definition and declaration"

    Read K&R, and see this thread:
    http://www.keil.com/forum/docs/thread1847.asp

    Basically, a definition creates code and/or data; a declaration merely informs the compiler about code and/or data.

    Therefore, declarations are good in headers; definitions are bad!

    "compiler does not allow me to declare a variable in H file"

    Nonsense!
    The compiler doesn't care - it will let you have both definitions and declarations in headers.

    If you get errors when you declare (or, more likely, define) a variable in a Header file, it has nothing to do with the fact that it's in a header file per se; more likely you are falling into one of the pitfalls which is why we say: don't define code or data in headers!

Children
No data