On Tue, 22 Jul 2008 03:38:00 -0700, Alan Williams-Key
<Al*************@discussions.microsoft.comwrote:
>When I compile this on my PC I get the following
D:\...\File.cpp(32806) : warning C4305: 'initializing' : truncation from
'int' to 'short'
D:\...\File.cpp(32806) : warning C4309: 'initializing' : truncation of
constant value
Thanks. I found this one using your suggestion. Within the ASSERT there was
"AfxAssertFailedLine(THIS_FILE, 32822)"
and I guess 32822 is the fly in the ointment.
Given these declarations, and assuming a 32 bit (or more) compiler, I don't
see why that's a problem:
#define ASSERT(f) DEBUG_ONLY((void) ((f) || !::AfxAssertFailedLine(THIS_FILE, __LINE__) || (AfxDebugBreak(), 0)))
BOOL AFXAPI AfxAssertFailedLine(LPCSTR lpszFileName, int nLine);
The function you presented earlier was:
void test()
{
int i = 1;
ASSERT(i==0);
}
What does the line "int i = 1;" look like in the /P file? Moreover, I can't
repro the problem in VC 2008 by running this program and compiling its
output:
// a.cpp
#include <stdio.h>
int main()
{
FILE* fp = fopen("b.cpp", "w");
fputs("#include <stdio.h>\n", fp);
fputs("void print(int n) { printf(\"%d\\n\", n); }\n", fp);
for (int i = 0; i < 32900; ++i)
fputc('\n', fp);
fputs("int main() { print(__LINE__); }\n", fp);
fclose(fp);
}
So either int is getting replaced by short in your file (which makes me
wonder how you can link), there's a compiler bug, or the problem lies
elsewhere. What version of the compiler are you using?
>The other problems (5 of them)
are similar. The debug version is including a line number in the debug
version of library routines (eg the "new" statement).
OK, I have a large file and I guess this just means my debug builds will
generate these warning messages. Thanks for your help.
Unless it's machine-generated, I'd want to split it into manageable pieces
preferably no larger than a few hundred lines each even if I wasn't getting
errors.
--
Doug Harrison
Visual C++ MVP