Click here to Skip to main content
16,010,918 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Header file Tips wanted Pin
Carlos Antollini11-Mar-02 3:31
Carlos Antollini11-Mar-02 3:31 
GeneralRe: Header file Tips wanted Pin
Tomasz Sowinski11-Mar-02 3:41
Tomasz Sowinski11-Mar-02 3:41 
GeneralRe: Header file Tips wanted Pin
Joao Vaz11-Mar-02 4:52
Joao Vaz11-Mar-02 4:52 
GeneralRe: Header file Tips wanted Pin
Tomasz Sowinski11-Mar-02 5:01
Tomasz Sowinski11-Mar-02 5:01 
GeneralRe: Header file Tips wanted Pin
Joao Vaz11-Mar-02 6:29
Joao Vaz11-Mar-02 6:29 
GeneralRe: Header file Tips wanted Pin
Ramon Casellas11-Mar-02 4:50
Ramon Casellas11-Mar-02 4:50 
GeneralRe: Header file Tips wanted Pin
Joao Vaz11-Mar-02 4:56
Joao Vaz11-Mar-02 4:56 
GeneralRe: Header file Tips wanted Pin
Rick York11-Mar-02 9:52
mveRick York11-Mar-02 9:52 
One thing I always do, and I picked this up from reading windoze SDK headers, is I put this little block at the front of all my headers :

#ifdef _HEADER_H
#error repeated include of this file
#else
#define _HEADER_H
#endif

Then substitute the name of your header file in place of HEADER.

Any time I want to include the file I use this :

#ifndef _HEADER_H
#include "Header.h"
#endif

This forces one and only inclusion of a given header file without having to parse each one a whole bunch of times. This really adds up in large projects.

One key to making this work is to have a consistent define pattern for the header files. I always use the one shown. I dislike the GUID method but that's just me.

This is also portable unlike MFC's pragma once method in case that matters.

Another frequent header file headache is the issue of global variables and the use of extern. Here is what I do.

In one central macro definition header define this :

#ifdef _DEFINE_GLOBALS
#define Global
#else
#define Global extern
#endif

Then you can declare global variables like this :

Global int GlobalInteger_1;
Global int GlobalInteger_2;

If you want them initialized then do this :

#ifdef _DEFINE_GLOBALS

int GlobalInteger_1 = 42;

#else // _DEFINE_GLOBALS

Global int GlobalInteger_1;

#endif // _DEFINE_GLOBALS


Prior to include the header with the global declarations, do this :

#define _DEFINE_GLOBALS
#include "Globals.h"

NOTE: the _DEFINE_GLOBALS may only be defined one and only one time. I usually do it in my application class module.

The advantages of this scheme are that you only have to maitain one file of declarations and the extern issue is taken care of.

GeneralSendMessage and ListBox Pin
User 665811-Mar-02 2:06
User 665811-Mar-02 2:06 
GeneralRe: SendMessage and ListBox Pin
Ravi Bhavnani11-Mar-02 2:21
professionalRavi Bhavnani11-Mar-02 2:21 
GeneralRe: SendMessage and ListBox Pin
User 665811-Mar-02 2:27
User 665811-Mar-02 2:27 
GeneralRe: SendMessage and ListBox Pin
Ravi Bhavnani11-Mar-02 2:36
professionalRavi Bhavnani11-Mar-02 2:36 
GeneralRe: SendMessage and ListBox Pin
User 665811-Mar-02 2:34
User 665811-Mar-02 2:34 
GeneralRe: SendMessage and ListBox Pin
Ravi Bhavnani11-Mar-02 4:10
professionalRavi Bhavnani11-Mar-02 4:10 
GeneralRe: SendMessage and ListBox Pin
User 665811-Mar-02 4:34
User 665811-Mar-02 4:34 
GeneralRe: Just found strange behavior Pin
User 665811-Mar-02 3:07
User 665811-Mar-02 3:07 
GeneralRe: SendMessage and ListBox Pin
Tomasz Sowinski11-Mar-02 3:52
Tomasz Sowinski11-Mar-02 3:52 
GeneralRe: SendMessage and ListBox Pin
User 665811-Mar-02 4:00
User 665811-Mar-02 4:00 
GeneralRe: SendMessage and ListBox Pin
Tomasz Sowinski11-Mar-02 4:16
Tomasz Sowinski11-Mar-02 4:16 
GeneralRe: SendMessage and ListBox Pin
User 665811-Mar-02 4:21
User 665811-Mar-02 4:21 
GeneralRe: SendMessage and ListBox Pin
Tomasz Sowinski11-Mar-02 4:23
Tomasz Sowinski11-Mar-02 4:23 
GeneralRe: SendMessage and ListBox Pin
User 665811-Mar-02 4:29
User 665811-Mar-02 4:29 
GeneralRe: SendMessage and ListBox Pin
Tomasz Sowinski11-Mar-02 4:37
Tomasz Sowinski11-Mar-02 4:37 
GeneralRe: THANKS A LOT!!!! Pin
User 665811-Mar-02 4:46
User 665811-Mar-02 4:46 
GeneralRe: THANKS A LOT!!!! Pin
Tomasz Sowinski11-Mar-02 4:56
Tomasz Sowinski11-Mar-02 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.