How to prevent multiple definitions in C?

后端 未结 7 1054
失恋的感觉
失恋的感觉 2020-12-08 00:36

I\'m a C newbie and I was just trying to write a console application with Code::Blocks. Here\'s the (simplified) code: main.c:

#include 
#incl         


        
7条回答
  •  温柔的废话
    2020-12-08 00:56

    If you're using Visual Studio you could also do "#pragma once" at the top of the headerfile to achieve the same thing as the "#ifndef ..."-wrapping. Some other compilers probably support it as well .. .. However, don't do this :D Stick with the #ifndef-wrapping to achieve cross-compiler compatibility. I just wanted to let you know that you could also do #pragma once, since you'll probably meet this statement quite a bit when reading other peoples code.

    Good luck with it

提交回复
热议问题