In C, how do I restrict the scope of a global variable to the file in which it's declared?

后端 未结 4 1886
灰色年华
灰色年华 2020-12-18 01:52

I\'m new to C. I have a book in front of me that explains C\'s \"file scope\", including sample code. But the code only declares and initializes a file scoped variable - it

4条回答
  •  独厮守ぢ
    2020-12-18 02:31

    Don't ever #include a .c file like you are doing there. The language allows it, but C coders just don't do that, so you will confuse the heck out of people if you do it. Most likely including yourself.

    "#include" means "Compiler, please go to that other file and tack it to the front of this one before you start compiling my code."

    I once lost a whole day in total confusion because one of the vxWorks source files did this. I'm still POed at them over that.

提交回复
热议问题