Bug 5982 - Converting from one data type to another shows an overflow error
Summary: Converting from one data type to another shows an overflow error
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2012-07-04 11:48 UTC by jlee10
Modified: 2012-07-05 09:44 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description jlee10 2012-07-04 11:48:38 UTC
In attempting to define a short, I used:

private const short asdf = 0x82CD;

...and I got an error saying "Constant value '33485' cannot be converted to a 'short'", even though it should be valid. I can bypass this by using:

private const short asdf = -32051;
Comment 1 Marek Safar 2012-07-05 04:13:59 UTC
short range is -32768 to 32767
Comment 2 jlee10 2012-07-05 09:09:57 UTC
But 0x82CD should be a valid short, since:
0x82CD => 1000 0010 1100 1101 => -32051.

Is this correct?
Comment 3 Marek Safar 2012-07-05 09:43:11 UTC
Not really 0x82CD is a literal value which defaults to int

You probably want to write this

const short s = unchecked((short)0x82CD);
Comment 4 jlee10 2012-07-05 09:44:06 UTC
Ah, alright. Thank you Marek.