473,396 Members | 1,933 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.

VS2005 Pro SP1 and C4244

I've just upgraded to SP1, and am seeing C4244 warnings on code like the
following:

void fn()
{
short a = 1;
short b = 2;

a += b; // warning C4244: '+=' : conversion from 'int' to
'short', possible loss of data i:\2005\CPP\NDS\testmsl\Calsetng.cpp 168

// but
a = a + b; // doesn't give a warning.
}

I'm not sure if this was wrong before SP1 or not, but it's reported as fixed
here:
https://connect.microsoft.com/Visual...edbackID=99575

Does anyone else get this error with or without SP1?

Anthony Wieser
Wieser Software Ltd
Dec 28 '06 #1
5 1079
>I've just upgraded to SP1, and am seeing C4244 warnings on code like the
>following:

void fn()
{
short a = 1;
short b = 2;

a += b; // warning C4244: '+=' : conversion from 'int' to
'short', possible loss of data i:\2005\CPP\NDS\testmsl\Calsetng.cpp 168

// but
a = a + b; // doesn't give a warning.
}

I'm not sure if this was wrong before SP1 or not, but it's reported as fixed
here:
https://connect.microsoft.com/Visual...edbackID=99575

Does anyone else get this error with or without SP1?
Anthony,

I'm surprised by the comment to that bug report. I believe this is one
of those C/C++ quirks that throws most of us at some time or another.

As far as I know it's expected behaviour not a bug.

Dave
Dec 28 '06 #2
> a += b; // warning C4244: '+=' : conversion from 'int' to
>>'short', possible loss of data i:\2005\CPP\NDS\testmsl\Calsetng.cpp 168

// but
a = a + b; // doesn't give a warning.
}

I'm not sure if this was wrong before SP1 or not, but it's reported as
fixed
here:
https://connect.microsoft.com/Visual...edbackID=99575

Does anyone else get this error with or without SP1?

Anthony,

I'm surprised by the comment to that bug report. I believe this is one
of those C/C++ quirks that throws most of us at some time or another.

As far as I know it's expected behaviour not a bug.
This is documented in MSDN if you look for the += operator documentation
(you have to follow one or two links from there)
Basically, the C standard says that for those operators, the arguments are
automatically converted to int.
It's one of those things that must have seemed like a good idea at the
time...

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Dec 28 '06 #3

"Bruno van Dooren [MVP VC++]" <br**********************@hotmail.comwrote
in message news:OU**************@TK2MSFTNGP02.phx.gbl...
| > a += b; // warning C4244: '+=' : conversion from 'int' to
| >>'short', possible loss of data i:\2005\CPP\NDS\testmsl\Calsetng.cpp 168
| >>
| > // but
| > a = a + b; // doesn't give a warning.
| >>}
| >>
| >>I'm not sure if this was wrong before SP1 or not, but it's reported as
| >>fixed
| >>here:
|
>>https://connect.microsoft.com/Visual...edbackID=99575
| >>
| >>Does anyone else get this error with or without SP1?
| >
| Anthony,
| >
| I'm surprised by the comment to that bug report. I believe this is one
| of those C/C++ quirks that throws most of us at some time or another.
| >
| As far as I know it's expected behaviour not a bug.
|
| This is documented in MSDN if you look for the += operator documentation
| (you have to follow one or two links from there)
| Basically, the C standard says that for those operators, the arguments are
| automatically converted to int.
| It's one of those things that must have seemed like a good idea at the
| time...
|

The documentation seems a bit misleading:
it says here:
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vclang/html/a6135e34-4fce-4c79-87b6-b6447db3507e.htm
"The assignment operators return the value of the object specified by the
left operand after the assignment. The resultant type is the type of the
left operand. "

Also, the documentation here:
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vclang/html/b028cf35-2ff1-4f14-9027-fd53ebec8aa0.htm
says:
"+=
Add the value of the second operand to the value of the first operand;
store the result in the object specified by the first operand.

"
So the two lines below should be equivalent:
> a += b; // warning C4244: '+=' : conversion from 'int' to
'short'.
| > // but
| > a = a + b; // doesn't give a warning.
|

Where's your reference that implied that it was ok to convert to int? I
can't find it anywhere (but maybe my google searches are wrong).

Anthony Wieser
Wieser Software Ltd

Dec 28 '06 #4
The documentation seems a bit misleading:
it says here:
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vclang/html/a6135e34-4fce-4c79-87b6-b6447db3507e.htm
"The assignment operators return the value of the object specified by the
left operand after the assignment. The resultant type is the type of the
left operand. "

Also, the documentation here:
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vclang/html/b028cf35-2ff1-4f14-9027-fd53ebec8aa0.htm
says:
"+=
Add the value of the second operand to the value of the first operand;
store the result in the object specified by the first operand.
Hi,

http://msdn2.microsoft.com/en-us/library/k630sk6z.aspx
bullet point 1 applies.

See here for the rules:
http://msdn2.microsoft.com/en-us/library/3t4w2bkb.aspx

The behavior of += is not explicitly specified, but the you can see that the
documentation allows for it. It is allowed by the C/C++ standards as well.

I still think it is idiotic that += does this, since it is supposed to be
equal to = +.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Dec 29 '06 #5

"Bruno van Dooren [MVP VC++]" <br**********************@hotmail.comwrote
in message news:OH*************@TK2MSFTNGP02.phx.gbl...
|The documentation seems a bit misleading:
| it says here:
| >
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vclang/html/a6135e34-4fce-4c79-87b6-b6447db3507e.htm
| "The assignment operators return the value of the object specified by
the
| left operand after the assignment. The resultant type is the type of the
| left operand. "
| >
| Also, the documentation here:
| >
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vclang/html/b028cf35-2ff1-4f14-9027-fd53ebec8aa0.htm
| says:
| "+=
| Add the value of the second operand to the value of the first
operand;
| store the result in the object specified by the first operand.
|
| Hi,
|
| http://msdn2.microsoft.com/en-us/library/k630sk6z.aspx
| bullet point 1 applies.
|
| See here for the rules:
| http://msdn2.microsoft.com/en-us/library/3t4w2bkb.aspx
|
| The behavior of += is not explicitly specified, but the you can see that
the
| documentation allows for it. It is allowed by the C/C++ standards as well.
|
| I still think it is idiotic that += does this, since it is supposed to be
| equal to = +.
|
| --
|
| Kind regards,
| Bruno van Dooren
| br**********************@hotmail.com
| Remove only "_nos_pam"
|
|

OK, I see here that it says:
If none of the above conditions are met, both operands are converted to type
int.

So that means the compiler really should be warning me in the second case
too, where I write

short a=1;
short b=2;

a = a + b;

That's even more depressing! So in the next version of the compiler, I'll
get even more warnings.

Maybe the next version will have C4416 defined.

// warning C4416: Ha Ha Ha! You're still using 16 bit values!

--
Anthony Wieser
Wieser Software Ltd

Dec 29 '06 #6

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

Similar topics

5
by: GaryDean | last post by:
(my original post was inaccurate but this post accurately describes what I think is a very bad vs2005 bug) short description... Deleting a dataset and recreating it from the dataadapter causes...
10
by: musosdev | last post by:
Hi guys I'm trying to migrate to VS2005... I've managed to do that, but realised I'd opened my web projects as file projects, and I'm getting the error about network BIOS command limit. ...
6
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a...
7
by: Frank Rizzo | last post by:
Is it me or is the speed of VS2005 actually slower than VS2003? The startup is pretty bad - even though I changed VS to display an empty environment. When I create a new form and want to change...
9
by: yevvi | last post by:
Hi, We have a product with bunch of dlls which are now built with Visual Studio 2003. We want to switch the build to use VS2005. I have read that in VS2005 runtime libraries come as...
15
by: Joseph Geretz | last post by:
OK, I'll admit it up front - I just don't get it. Here's our previous VS2003 development model. Developers develop the WS solution on their own workstations, using their own IIS web servers...
0
by: malini | last post by:
Hi I am new to vc++. currently using VC 2005 version 8 Someone help me solve this. lpppublishdimincent.cpp(294) : warning C4244: 'argument' : conversion from 'const lpmINT64' to 'char', possible...
5
by: Gumby | last post by:
Hi there! A "special" project team in our department has decided to purchase XMLSpy. We standardize on VS2005 as our IDE and up to now everyone has used the XML parser in VS2005. Are there...
1
by: zelmila19 | last post by:
Hello, this part of my program: int shotDistance(int a) { int min = a * .8, max = a * 1.2; //Defines the minimum and maximum range of the club. srand ((unsigned int) time(NULL)); a...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
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
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.