warning C4244 (VC7.0) unexplained!!!

G

Geoff Noel

hi, the following code generates warning C4244 :'+=':conversion from 'int'
to 'short' possible loss of data

void main()
{
short a=0, b=0;
a += b;
}

why?? thanks.
 
J

Jay Nabonne

hi, the following code generates warning C4244 :'+=':conversion from 'int'
to 'short' possible loss of data

void main()
{
short a=0, b=0;
a += b;
}

why?? thanks.

Click on the warning in the output window and hit F1.

Or go to http://msdn.microsoft.com and search for C4244.

Or ask in a Microsoft newsgroup.

- Jay
 
M

Mike Wahler

Geoff Noel said:
hi, the following code generates warning C4244 :'+=':conversion from 'int'
to 'short' possible loss of data

void main()

int main()
{
short a=0, b=0;
a += b;
}

why?? thanks.

The assignment expression has type 'int', due to
standard conversion rules. All values of type 'int'
won't necessary be representable by type 'short int',
thus the warning.

Now my 'why' question: why not just use type 'int'?

Re your use of the word 'unexplained' in your message
subject:

I don't have VC7, but I have VC6, which
documents error C4244 thus:

============================================================
Compiler Warning (levels 3 and 4) C4244

'conversion' conversion from 'type1' to 'type2',
possible loss of data

An integral type was converted to a smaller integral type.
This is a level-4 warning if type2 is int and the size of
type1 is smaller than int. Otherwise it is a level-3 warning.

The conversion may have a problem due to implicit integral

conversions. For example:

short a, b, c;
a = b + c; // warning
============================================================


-Mike
 
V

Victor Bazarov

Geoff Noel said:
hi, the following code generates warning C4244 :'+=':conversion from
'int' to 'short' possible loss of data

void main()
{
short a=0, b=0;
a += b;
}

why?? thanks.

It's because your 'main' returns void. It should return int.

No, I am just joking. It's probably a bug in the compiler.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top