Thread: global variable and header question

  1. #1

    Question global variable and header question

    I'm new to C++ i'm coding in unmanaged C++.NET (unmanaged makes it standard C++). I have a question about global variables. I need to define a global variable that is seen by all my files in my project. I use "basicheader.h" to store all my definitions for all my files since all my files use everything in it. This is the way I'm doing global variables:

    int a, b,c;

    extern int a,b,c;

    include "basicheader.h"

    include "basicheader.h"

    I'm figuring that this is exporting the variable dll style. And compiling takes a long time. Is there any other way to do global variables? And one more thing, why does everytime I do an error in "basicheader.h" I see it many times in the output? Like, I get the same error many times. I'm guessing it compiles the file everytime it's included but I put "#pragma once" (the same to #!indef basicheader | #define basicheader | ... | #edef; or something like that, I'm not sure of the keywords ). I'm not using a precompiled header.

    Thanks in advance,

  2. #2

    Cmon People...

    C'mon....I really need help!!! Please!!!


  3. #3
    You see the error multiple times because an #include causes the text of the header file to be directly included (hence #include) into the .cpp file, before it is compiled. (Thats why #include is a preprocessor statement, because it is doing pre-compilation processing). So it would make sense that if you are including an error (via an include file) in multiple .cpp files, that you would see an error in each (since header files technically aren't compiled (separately at least), only .cpp files are).

    As to the problem of taking a long time to compile, you could try using VC's precompiled header option. On VC6, you will find it under Project/Settings, flip to the c++ tab, and pull the combo box down to precompiled header. Then there is a radio button that you select "Use precompiled header through: ", and you will be required to type the header file name that you want precompiled, ie: "MyHeader.h" ( quotes included ). This may or may not fix your problem.

    BTW, using global variables in this way has nothing to do with .dll's or exporting.

    Good luck.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Regarding global variable.
    By sunny_master_07 in forum C++ Programming
    Replies: 1
    Last Post: 07-29-2008, 06:38 AM
  3. Header question
    By Meloshski in forum C Programming
    Replies: 4
    Last Post: 07-04-2004, 06:42 AM
  4. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. C global variables
    By Dohojar in forum C Programming
    Replies: 18
    Last Post: 02-25-2002, 12:00 PM