Link to home
Start Free TrialLog in
Avatar of jper_hm
jper_hmFlag for Singapore

asked on

Initializing warning messages - How to trouble sheet?

Hi Experts,

After adding some codes, I get many 'initializing' warning messages, but with addresses pointing to the end of OTHER sub-routines unrelated to the new codes. The warning messages all come in pairs like this:

warning C4305: 'initializing' : truncation from 'int' to 'short'
warning C4309: 'initializing' : truncation of constant value

Each pair points to the closing } of other sub-routines. What could have caused the warnings? Are these warnings harmful? It seems to be hinting that something in code is wrong, so I think it needs to be corrected though running the program does not reveal any problems.
 
How to trouble shoot? Thank you.
Avatar of jkr
jkr
Flag of Germany image

Are you using ATL? If so, take a look at http://support.microsoft.com/kb/250847 ("BUG: ATL Connection Point Wizard Generated Code for Event with VARIANT Argument Gives C4305 Warning")
Avatar of jper_hm

ASKER

Thanks, jkr. No, I am not using ATL, but I will look at this article anyway.

Any other tips?
Avatar of jper_hm

ASKER

One observation is that every sub-routine that all of a sudden has these warnings has a "new" in the declaration, such as:

LPTSTR buffer = new char[10];
or
pDialog = new CDownloadTickers();

There are 18 sub-routines. So it may not be a coincidence.
ASKER CERTIFIED SOLUTION
Avatar of jper_hm
jper_hm
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jper_hm

ASKER

I think I have sort of found the problem, but don't know why and how to fix it. Let me elaborate.

I try to move one of the short subroutines that has the LPTSTR buffer = new char[10]; in it. When it is nearer the bottom of the .cpp file, the warning occurs. As I move up nearer to the top of the file, the warning message disappears. At first I thought the offending code block must be the one that when this short-subroutine moved on top of it, the warning disappeared, and when it was below it, it appeared. But NO, when the 'offending' block was commented out and the codes duplicated and moved to the bottom of the, the warning was still there. But when I removed the commented block, it went away!

The only explanation of all these observations is that In VC++ 6.0 (which I am using), when a .cpp file is BIG, down to some line count of text count, if there is LPTSTR buffer = new char[10]; or pDialog = new CDownloadTickers(); lines, I would see warning messages for the subroutines! Although I still cannot believe that this is true!

Anyone has such an experience?
Often at th top of MFC cpp file there is macro:

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

Chack if it is write correctly
Avatar of jper_hm

ASKER

I have this at the top:

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

Anything wrong? I don't quite understand the macros...
These macros are OK, they just set the debug allocators to be used in debug builds.

>>I try to move one of the short subroutines that has the LPTSTR buffer = new
>>char[10]; in it. When it is nearer the bottom of the .cpp file, the warning
>>occurs. As I move up nearer to the top of the file, the warning message
>>disappears.

Are you compiling as UNICODE or ANSI?
Avatar of jper_hm

ASKER

Thanks. I am compiling as ANSI.
Avatar of jper_hm

ASKER

It looks like there is no better solution than what I have used. That is to change from
LPTSTR buffer = new char[10];
to
char buffer[10];

I will close this question.
Avatar of stev75
stev75

this is a problem of DEBUG_NEW in BIG .cpp files (more than 32767 lines) in VS6.
just place the functions using "new" at the beginning, the warnings won't pop up again!