473,396 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Bizarre compiler error

I am being bugged by some bizarre compiler errors when compiling in debug
configuration (but not in release). Here is a test function...

void test()
{
int i = 1;
ASSERT(i==0);
}

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

Does anyone have any ideas what is causing this. As far as I can see there
is no truncation going on in this function.

Alan
Jul 21 '08 #1
6 1602
On Mon, 21 Jul 2008 09:26:01 -0700, Alan Williams-Key
<Al*************@discussions.microsoft.comwrote:
>I am being bugged by some bizarre compiler errors when compiling in debug
configuration (but not in release). Here is a test function...

void test()
{
int i = 1;
ASSERT(i==0);
}

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

Does anyone have any ideas what is causing this. As far as I can see there
is no truncation going on in this function.
My first thought is that the error is occurring in a different function
than you posted. Assuming this is the right function, and ASSERT does what
I think it does, the error has to be due to either a preprocessor mishap or
a compiler bug. You can compile with /P to examine the preprocessor output.
You can compile the function in its own file to rule out a compiler bug
triggered by whatever precedes the function in your very large source file.

--
Doug Harrison
Visual C++ MVP
Jul 21 '08 #2


"Doug Harrison [MVP]" wrote:
On Mon, 21 Jul 2008 09:26:01 -0700, Alan Williams-Key
<Al*************@discussions.microsoft.comwrote:
I am being bugged by some bizarre compiler errors when compiling in debug
configuration (but not in release). Here is a test function...

void test()
{
int i = 1;
ASSERT(i==0);
}

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

Does anyone have any ideas what is causing this. As far as I can see there
is no truncation going on in this function.

My first thought is that the error is occurring in a different function
than you posted. Assuming this is the right function, and ASSERT does what
I think it does, the error has to be due to either a preprocessor mishap or
a compiler bug. You can compile with /P to examine the preprocessor output.
You can compile the function in its own file to rule out a compiler bug
triggered by whatever precedes the function in your very large source file.

--
Doug Harrison
Visual C++ MVP
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. 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.

Alan
Jul 22 '08 #3
Alan Williams-Key wrote:
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. 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.
Alan:

Why don't you just split this file up into smaller pieces?

--
David Wilkinson
Visual C++ MVP
Jul 22 '08 #4
Yep, that's the obvious thing to do. I was not experienced with VS C++ when I
started this project and if I were starting it now I would split my classes
into files completely differently. It's somthing that has to be done with
care, though, and although I can split a class out into a separate file I'm
not sure if VS will recognise its new home if I then add a new function
member. Is there a trick I need to know?

Alan

"David Wilkinson" wrote:
Alan Williams-Key wrote:
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. 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.

Alan:

Why don't you just split this file up into smaller pieces?

--
David Wilkinson
Visual C++ MVP
Jul 22 '08 #5
Alan Williams-Key wrote:
Yep, that's the obvious thing to do. I was not experienced with VS C++ when I
started this project and if I were starting it now I would split my classes
into files completely differently. It's somthing that has to be done with
care, though, and although I can split a class out into a separate file I'm
not sure if VS will recognise its new home if I then add a new function
member. Is there a trick I need to know?
Alan:

It shouldn't be any problem. You don't have to split the header file if you
don't want; just split the implementation file.

I assume this file is not all one class? But even if it is, you can still split
the implementation into multiple pieces.

--
David Wilkinson
Visual C++ MVP
Jul 22 '08 #6
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
Jul 22 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alan Little | last post by:
This is very bizarre. Could someone else have a look at this? Maybe you can see something I'm overlooking. Go here: http://www.newsletters.forbes.com/enews/admin/deliver.php4 U: bugtest P:...
2
by: D. Alvarado | last post by:
Hello, I have moved my site to a hosting environment with PHP 4. But I get this bizarre error upon invoking session_start() Warning: session_start():...
6
by: rbazinet | last post by:
I have a VS 2003 C# project, web app with a bunch of DLL's. When I compile my project I often times get this message: Unexpected error creating debug information file 'C:\DevProjects\Allstar...
1
by: Richard | last post by:
Here's a Bizarre one: I have a C# service program. The service registers and runs fine on one machine but when I copy the EXE to a second machine and try to use InstallUtil to register the...
4
by: Neo Geshel | last post by:
Just moved to C# from VB.NET, frustrated to hell and back by inability to get much-copied (from about 20+ different resources) literal example to work. Master Page content: <meta...
0
by: ckfan.painter | last post by:
I've run into a seemingly bizarre problem with insert() for std::vector. (This was done on Microsoft Visual C++ 2005 express version 8...maybe it is a compiler specific bug?) Here's the code: ...
3
by: Don Miller | last post by:
I have a bizarre problem when I try to validate XML documents and their schemas once they have been opened and transfered to a Visual Web Developer 2005 Express project. I receive validation errors...
7
by: bajichuan | last post by:
Hello! I have the world's strangest linking error, and I'm hoping that someone can help me sort it out. I recently installed and compiled a library called LinBox without a problem. I have an...
20
by: Jasper | last post by:
I'm stumped. I'm calling a method that has keyword args, but not setting them, and yet one of them starts off with data?! The class definition begins like so: class BattleIntentionAction(...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.