473,804 Members | 3,067 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1618
On Mon, 21 Jul 2008 09:26:01 -0700, Alan Williams-Key
<Al************ *@discussions.m icrosoft.comwro te:
>I am being bugged by some bizarre compiler errors when compiling in debug
configuratio n (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.cp p(32806) : warning C4305: 'initializing' : truncation from
'int' to 'short'
D:\...\File.cp p(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.m icrosoft.comwro te:
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
"AfxAssertFaile dLine(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
"AfxAssertFaile dLine(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
"AfxAssertFaile dLine(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.m icrosoft.comwro te:
>When I compile this on my PC I get the following

D:\...\File.cp p(32806) : warning C4305: 'initializing' : truncation from
'int' to 'short'
D:\...\File.cp p(32806) : warning C4309: 'initializing' : truncation of
constant value

Thanks. I found this one using your suggestion. Within the ASSERT there was
"AfxAssertFail edLine(THIS_FIL E, 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((voi d) ((f) || !::AfxAssertFai ledLine(THIS_FI LE, __LINE__) || (AfxDebugBreak( ), 0)))
BOOL AFXAPI AfxAssertFailed Line(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
2172
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: test Enter 1 for "How many files in this delivery?" and select a file to upload, in one of the listed formats. Scroll down and click "Test Email".
2
1846
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(): open(/tmp/php/sessions/b/3/c/sess_b3c32ee4770b585fe49244f043b4dafa, O_RDWR) failed: No such file or directory (2) in /www/i/ikite/htdocs/admin/includes/functions/sessions.php on line 67 Could someone explain what this means, or what more information I should provide?
6
4024
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 Admin\Allstar.Common.DataAccess\obj\Debug\Allstar.Common.DataAccess.PDB' -- 'C:\DevProjects\Allstar Admin\Allstar.Common.DataAccess\obj\Debug\Allstar.Common.DataAccess.pdb: The process cannot access the file because it is being used by another...
1
1307
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 service on the second machine it bails out with: "No publicly exported Installers with RunInstaller attribute set to Yes" This is bizarre since the EXE does register on one machine. I checked and I am an Administrator on the target install machine...
4
2322
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 name="keywords" content="<asp:Literal ID="ltrlKeywords" Runat="server" />"></meta> Code-Behind:
0
371
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: //=================== // vector tester 3.cpp : main project file.
3
3589
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 for XML/XSDs that worked fine when first created in another environment (XMLSpy trial). I have a source XML document and an XSD file created wtih XMLSpy and stored in a separate folder. When I run a very simple VBScript to validate the XML...
7
1860
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 object-oriented software application, and I want it to call the library. When I add the following 3 lines (copied directly from the library tutorial), #include <linbox/field/modular.h> using namespace LinBox; typedef Modular<shortField;
20
1283
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( BattleAction ): def __init__( self, factionName, location, tactic='hold', targetFacName='', terrainArgs=, garrisonIds= ): self.terrainArgs = terrainArgs print terrainArgs
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9152
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.