D
D
DVamp1r32015-01-15 09:54:31
C++ / C#
DVamp1r3, 2015-01-15 09:54:31

Why are the addresses different (c++)?

When upgrading a project from VS2010 to VS2012, I encountered the following issue:

wchar_t var1[MAX_PATH];
wchar_t* tmpChar = var1;

The addresses are the same if the variables are within the scope of the method. If we have a situation, for example:
config.hpp
      static wchar_t var1[MAX_PATH];
main.cpp
     int main() {
          wchar_t* tmpChar = var1;
          return 0;
     }

then the addresses will be different (although the values ​​will be the same if var1 were defined). how to make it so that in the second case the addresses are the same?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maaGames, 2015-01-15
@DVamp1r3

static wchar_t
Each time the file is included, it creates its own copy of the var1 variable. Do it humanly, without static and with a declaration in the header and an implementation in the implementation file, and you will have one address.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question