NULL global variable

Discussion in 'C++' started by person, Jan 5, 2006.

  1. person

    person Guest

    Hi,

    I've got a global variable, type * var_name, declared in one .cpp file.
    I assign it a value inside one of the methods in that file. I extern
    it in other .cpp files. For some reason in all the other files it's
    NULL (thus causing my program to crash when I try to use it). I know
    it's getting assigned a legitimate value because I can use it
    successfully in the method right after it's assigned. The declaration
    is not static. Will someone please tell me what I'm doing incorrectly?
    It was working, then I had to go through a major overhaul of my
    including of .h files due to a bizarre inheritance problem. Now it
    doesn't work and I don't know if it's a side effect of the include
    exercise or if something else has gone haywire. Any help/ideas would
    be greatly appreciated.

    Thanks,
    Frank
    person, Jan 5, 2006
    #1
    1. Advertising

  2. person

    BigBrian Guest

    > Will someone please tell me what I'm doing incorrectly?

    That's difficult/impossible without seeing code. Without code
    anything would be just speculation and not quarenteed to be right
    anyway. Post a minimal amount of code which shows the problem, then we
    can tell you what's wrong.
    BigBrian, Jan 5, 2006
    #2
    1. Advertising

  3. person wrote:
    > I've got a global variable, type * var_name, declared in one .cpp file.
    > I assign it a value inside one of the methods in that file. I extern
    > it in other .cpp files. For some reason in all the other files it's
    > NULL (thus causing my program to crash when I try to use it). I know
    > it's getting assigned a legitimate value because I can use it
    > successfully in the method right after it's assigned. The declaration
    > is not static. Will someone please tell me what I'm doing incorrectly?


    Simple. You're not following the recommendations of FAQ 5.8.

    > It was working, then I had to go through a major overhaul of my
    > including of .h files due to a bizarre inheritance problem. Now it
    > doesn't work and I don't know if it's a side effect of the include
    > exercise or if something else has gone haywire. Any help/ideas would
    > be greatly appreciated.


    Recompile/Rebuild all.

    V
    Victor Bazarov, Jan 5, 2006
    #3
  4. person

    Mike Wahler Guest

    "person" <> wrote in message
    news:...
    > Hi,
    >
    > I've got a global variable, type * var_name, declared in one .cpp file.
    > I assign it a value inside one of the methods in that file. I extern
    > it in other .cpp files. For some reason in all the other files it's
    > NULL (thus causing my program to crash when I try to use it). I know
    > it's getting assigned a legitimate value because I can use it
    > successfully in the method right after it's assigned. The declaration
    > is not static. Will someone please tell me what I'm doing incorrectly?
    > It was working, then I had to go through a major overhaul of my
    > including of .h files due to a bizarre inheritance problem. Now it
    > doesn't work and I don't know if it's a side effect of the include
    > exercise or if something else has gone haywire. Any help/ideas would
    > be greatly appreciated.


    You have a bug on line 42.

    -Mike
    Mike Wahler, Jan 6, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    26,584
    Mike Schilling
    Mar 29, 2006
  2. Bryan Parkoff
    Replies:
    2
    Views:
    6,489
  3. Replies:
    1
    Views:
    382
    Michael Ekstrand
    Aug 21, 2005
  4. moxm
    Replies:
    19
    Views:
    969
    Flash Gordon
    Aug 19, 2005
  5. PS
    Replies:
    8
    Views:
    298
Loading...

Share This Page