include-guards

Difference between pragma once inside and outside include guards?

雨燕双飞 提交于 2019-12-05 02:30:27
Is there any difference between placing the #pragma once inside the include guards as opposed to outside? case 1: #ifndef SOME_HEADER_H #define SOME_HEADER_H #pragma once case 2: #pragma once #ifndef SOME_HEADER_H #define SOME_HEADER_H I'm just wondering out of curiosity if there's any special cases where I should prefer one or the other (case 1 or case 2) since I've decided to combine both (pragma and header guards) in my code. EDIT: I think you guys are misinterpreting my question... I am asking about the location of pragma once , not pragma once -vs- header guards. There's a subtle

Multiple inclusion in multiple files

ε祈祈猫儿з 提交于 2019-12-04 19:13:40
I am making a small game. In BattleRecord.h: #ifndef _CHARACTER_H_ #define _CHARACTER_H_ #include "Character.h" #endif class BattleRecord { public: Character Attacker; Character Defender; Status status; int DamageDealt; int GoldEarned; int ExpGained; }; In Character.h: #ifndef _EQUIPMENT_H_ #define _EQUIPMENT_H_ #include "Equipment.h" #endif class BattleRecord; class Character { BattleRecord AttackEnemy(Character &Enemy); } In BattleRecord.h: #ifndef _CHARACTER_H_ #define _CHARACTEr_H_ #include "Character.h" #endif #ifndef _BATLE_RECORD_H_ #define _BATLE_RECORD_H_ #include "BattleRecord.h"

Should I still use #include guards AND #pragma once?

ぐ巨炮叔叔 提交于 2019-12-03 23:27:30
http://en.wikipedia.org/wiki/Pragma_once Should I still use include guards when all of these compilers support #pragma once ? A lot of responses on stack overflow say to use both for compatibility, but I'm not sure if that still rings true. What compilers today don't support #pragma once ? I am not sure if using both was just a recommendation before it became widley adopted, or if there are still very good reasons to use both methods. Any examples of when only using #pragma once will cause problems? It depends on how much portable your program is expected to be. As long as you are writing a

Is there any mechanism in Shell script alike “include guard” in C++?

我是研究僧i 提交于 2019-12-03 08:04:40
let's see an example: in my main.sh, I'd like to source a.sh and b.sh. a.sh, however, might have already sourced b.sh. Thus it will cause the codes in b.sh executed twice. Is there any mechanism alike "include guard" in C++? If you're sourcing scripts, you are usually using them to define functions and/or variables. That means you can test whether the script has been sourced before by testing for (one of) the functions or variables it defines. For example (in b.sh ): if [ -z "$B_SH_INCLUDED" ] then B_SH_INCLUDED=yes ...rest of original contents of b.sh fi There is no other way to do it that I

Doxygen demands that an include-guard be documented

吃可爱长大的小学妹 提交于 2019-12-01 18:18:42
问题 Please do not mind the strangeness of the following minimal example (I would have to make it much larger to justify why I am doing things this way): File test.cpp: #include "a.h" int main() { return 0; } File a.h: namespace N { // without namespace all is well! #include "b.h" } File b.h: /// \file #ifndef GUARD #define GUARD struct A {}; #define CMD 5 // without this, all is well! #endif Doxygen 1.8.11 complains: warning: Member GUARD (macro definition) of file a.h is not documented. The

Doxygen demands that an include-guard be documented

一曲冷凌霜 提交于 2019-12-01 18:12:50
Please do not mind the strangeness of the following minimal example (I would have to make it much larger to justify why I am doing things this way): File test.cpp: #include "a.h" int main() { return 0; } File a.h: namespace N { // without namespace all is well! #include "b.h" } File b.h: /// \file #ifndef GUARD #define GUARD struct A {}; #define CMD 5 // without this, all is well! #endif Doxygen 1.8.11 complains: warning: Member GUARD (macro definition) of file a.h is not documented. The first interesting thing is that the warning mentions a.h . The second one is that if either of the

C++ Include Guards for Standard Headers

天涯浪子 提交于 2019-12-01 17:48:43
I am wondering if/ what include guards on files like windows.h , math.h , iostream , stdio ... etc. Since I have those headers included multiple times in different files. Do those files already have guards built in or is there a definition defined? I am just wondering what the standards are for that kind of thing. If you open the file to read the contents (you can even right click the include directive in most editors to open the file), you will see that include files usually start with something like: #ifndef _WINDOWS_ #define _WINDOWS_ ... So the first time it will go in the file since

What is proper LLVM header guard style?

扶醉桌前 提交于 2019-12-01 06:12:11
In clang tidy, the check [llvm-header-guard] looks for LLVM style header guards, but I can't find any examples of proper LLVM header guard style, specifically the structure of the name given to the define, the coding standards pages does not mention anything. Looking at the unit tests: https://github.com/llvm-mirror/clang-tools-extra/blob/master/unittests/clang-tidy/LLVMModuleTest.cpp it seems to accept a few variations on the commonly used patterns. For a file named include/llvm/ADT/foo.h the convention seems to be: #ifndef LLVM_ADT_FOO_H #define LLVM_ADT_FOO_H //... #endif // LLVM_ADT_FOO_H

Header/Include guards don't work?

馋奶兔 提交于 2019-12-01 05:56:01
For some reason, I'm getting multiple declarations of content within my header file even though I'm using header guards. My example code is below: main.c: #include "thing.h" int main(){ printf("%d", increment()); return 0; } thing.c: #include "thing.h" int increment(){ return something++; } thing.h: #ifndef THING_H_ #define THING_H_ #include <stdio.h> int something = 0; int increment(); #endif When I attempt to compile this, GCC says that I have multiple definitions of the something variable. ifndef should make sure that this doesn't happen, so I'm confused why it is. The include guards are

What is proper LLVM header guard style?

家住魔仙堡 提交于 2019-12-01 04:17:40
问题 In clang tidy, the check [llvm-header-guard] looks for LLVM style header guards, but I can't find any examples of proper LLVM header guard style, specifically the structure of the name given to the define, the coding standards pages does not mention anything. 回答1: Looking at the unit tests: https://github.com/llvm-mirror/clang-tools-extra/blob/master/unittests/clang-tidy/LLVMModuleTest.cpp it seems to accept a few variations on the commonly used patterns. For a file named include/llvm/ADT/foo