Home > Software engineering >  Run the MFC application an error in the doing.
Run the MFC application an error in the doing.

Time:09-25

I use Windows 7 wrote an MFC application of text processing, run on win10 program error, error reason is that I put a char * pointer to an int type to save, back to unavailable through (char *) turn back, then it is wrong, the following two statements, the first statement run correctly, run the second statement is wrong,,,
TRACE (" the test string is: % s \ n ", testarray); -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - & gt; The correct execution
TRACE (" the test string2 is: % s \ n ", (char *) (testarray) (int)); -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- & gt; Perform error

Is the system differences caused by?

CodePudding user response:

Int is 32 bits in the VS, if it is a 64 - bit system will naturally be truncated

Try __int64

CodePudding user response:

Look at the before and after conversion, if there is a change address

CodePudding user response:

Indeed as expected is truncated, thank zgl7903 oyljerry, char * type of Windows 7 is 4 bytes, doing and win10 are 8 bytes, system is 64 - bit, it's a pit, or don't use pointer to int storage of good, is the size of the pointer is determined by what people can say clear?

CodePudding user response:

Pointer specified size and compiler environment, WIN32 32-bit X64 64
For compatible compiler environment can use INT_PTR

TRACE (_T (" the test string2 is: % s \ n "), (char *) (INT_PTR testarray)); -
  • Related