global variable and header question

This is a discussion on global variable and header question within the C++ Programming forums, part of the General Programming Boards category; I'm new to C++ i'm coding in unmanaged C++.NET (unmanaged makes it standard C++). I have a question about global ...

  1. #1
    Unregistered
    Guest

    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:

    file1.cpp:
    int a, b,c;

    basicheader.h:
    extern int a,b,c;

    file2.cpp:
    include "basicheader.h"
    ...

    fileN.cpp
    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,
    Speedy

  2. #2
    Unregistered
    Guest

    Cmon People...

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

    Speedy

  3. #3
    Unregistered
    Guest
    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 Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. C global variables
    By Dohojar in forum C Programming
    Replies: 18
    Last Post: 02-25-2002, 11:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21