include-guards

C header file loops

I have a couple of header files, which boil down to: tree.h: #include "element.h" typedef struct tree_ { struct *tree_ first_child; struct *tree_ next_sibling; int tag; element *obj; .... } tree; element.h: #include "tree.h" typedef struct element_ { tree *tree_parent; char *name; ... } element; The ...

prevent direct access to a php include file.

I have a php file which I will be using as exclusively as an include. Therefor I would like to throw an error instead of executing it when it's accessed directly by typing in the URL instead of being included. Basically I need to do a check as follows in the php file: if ( $REQUEST_URL == $URL_OF_CURRENT_PAGE ) die ("Direct access not ...

suppress gcc warnings : "warning: this is the location of the previous definition"

Hi, I need a set of wrappers around the standard system calls-open,listen,etc. For these i have a few "#define" as in: #define open(a,b,c) JCL_Open(a,b,c) But when i compile the header and associated .c files, i am getting the following warning: /jcl_wrappers.h:114:1: warning: "open" redefined /jcl_wrappers.h:113:1: warning: this is ...

Is #pragma once a safe include guard?

I've read that there is some compiler optimization when using #pragma once which can result in faster compilation. I recognize that is non-standard, and thus could pose a cross-platform compatibility issue. Is this something that is supported by most modern compilers on non-windows platforms (gcc)? I want to avoid platform compilation...

Tricky include situation in C

I have a file named cpu.h that includes two other headers named register.h and addrmode.h. A cpu_t struct is defined in cpu.h that the two includes need for their functions. I try to include cpu.h in the two other include files, but nothing is included. I am guessing they are not included because of the include guards set up in cpu.h. Do...

how to include javascript files in Google Gears Worker (no DOM access)

how does one include other .js files in the .js of a Worker. Every "include" solution for Javascript that I've found does it by loading into a tag, which is not an option for Workers since they don't have access to the DOM. I see from your 950087/include-javascript-file-inside-javascript-file that using Ajax and eval() will do it. I ca...

SAS macro include guards

In other programming languages such as C++, include guards are used to prevent multiple inclusions of the same code. Like this in C++: #ifndef FOO_INCLUDED #define FOO_INCLUDED .... #endif Does it make sense to build inclusion guards into your SAS macro function definitions? And how should it be done? ...

Why C/C++'s #pragma_once isn't an ISO standard?

I am currently working on a big project and maintaining all those include guards makes me crazy! Writing it by hand is frustrating waste of time. Although many editors can generate include guards this doesn't help much: Editor generates guard symbol based on a filename. The problem occurs when you have headers with the same filename in...

Adding an include guard breaks the build

I added #ifndef..#define..#endif to a file of my project and the compiler fails. As soon as I remove it or put any other name in the define it compiles fine. What could be the problem? Sounds like the file is already declared, but I do not know where. I'm fine just removing it, but I really want to know why this is happening. error:...

In C and C++, why is each .h file usually surrounded with #ifndef #define #endif directives?

Why does each .h file starts with #ifndef #define #endif? We can certainly compile the program without those directives. ...

Are redundant include guards necessary?

Are 'redundant include guards' necessary in Codegear RAD Studio 2009? Is the compiler smart enough to deal with this on it's own? For example, I might have the following 'include guard' in foo.h: #ifndef fooH #define fooH // ... declaration here #endif and the following 'redundant include guard' in use_foo.h: #ifndef fooH #inclu...

Is there a good way to prevent jQuery from being redefined?

I encountered a problem that took me some time to debug where a plug-in that I was using for jQuery (in this case jFeed) was not working. The problem ended up being because we also used Amazon Associates product previews. The product previews code ends up including a number of other JS files through document.write(), including another co...

Template classes and include guards in C++

Is it wise to have include guards around template classes? Aren't template classes supposed to be reparsed each time you reference them with a different implementation? N.B In Visual C++ 2008 I get no errors combining the two... ...

Quick question regarding Conditional Compilation (ifndef)

Hello, This is quite probably a very silly question but I need to be sure. I've been given a class declaration in a header file eg. #ifndef file_H #define file_H class ex{ private: public: }; #endif and I've been required to write the method definitions in the same file, which I have done, my question is does the "#endif" stay wher...

C++ Header Guard issues

I am making a small C++ framework, which contains many .h and .cpp. I have created a general include which include all my .h file such as: framework.h #include "A.h" #include "B.h" #include "C.h" each .h header are protected with include guard such as #ifndef A_HEADER #define A_HEADER ... #endif The issues is, I would like to be...

Protecting one class from the bad programming of another?

Is there a way in PHP to try to include a file, but if the file contains errors that stop it from compiling to just skip that file from inclusion? ...

in C++ , what's so special about "_MOVE_H" ?

Hello, I have a C++ file like this #ifndef _MOVE_H #define _MOVE_H class Move { int x, y; public: Move(int initX = 0, int initY = 0) : x(initX), y(initY) {} int getX() { return x; } void setX(int newX) { x = newX; } int getY() { return y; } void setY(int newY) { y = newY; } }; #endif And to my amazement, all ...

Inclusion problem

I have an inclusion pattern as follows: /* * Class1.h */ #ifndef CLASS1_H_ #define CLASS1_H_ #include "Class2.h" namespace Class1_namespace { class Class1 { Class2* Class2_ptr; void Class1_member() { (*Class2_ptr).Class2_method(); } }; } #endif /* CLASS1_H_ */ /* * Class2.h */ #ifndef CLASS2_H_ #define CLASS2_H...

Are tokens after #endif legal?

I currently do the following and the compiler (MSVC2008 / as well as 2010) doesn't complain about it but I'm not sure if it's a bad idea or not: #ifndef FOO_H_ #define FOO_H_ // note, FOO_H_ is not a comment: #endif FOO_H_ I used to always write it as #endif // FOO_H_ but I caught myself not doing that today and thought it was strang...

Eclipse-CDT: Use Namespace in automatic generated include-guards

Does somebody know if (and how) it is possible to add the namespace in the name of the automatic generated include guards in Eclipse CDT, when creating a new class using the .hpp/.cpp templates? For me eclipse generates new class with namespace nicely, but the include-guards does not contain the namespace, so if the same header file exi...