I was experimenting with implicit typing of integer constants, and
found to my surprise that in MS C# 1.1 (VS.2003) you can write code
like
double Large = 18446744073709551615;
This is quite a bit bigger than ulong.MaxValue - in fact, it's
ulong.MaxValue * 2 + 1. I'm curious - could someone who has Mono
installed check to see if the Mono C# compiler can handle this line?
--
programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs 7 2066
Well... you're using a double there, not an int or a long. If you try a long
you'll probably get a compiler error along the lines of "can't do implicit
cast of 'ulong to long'. And if you cast it you'll still get an error and a
recommendation that you use unchecked code... which is not a good idea to
say the least =)
--
____________________
Klaus H. Probst, MVP http://www.vbbox.com/
"Jon Shemitz" <jo*@midnightbeach.com> wrote in message
news:40***************@midnightbeach.com... I was experimenting with implicit typing of integer constants, and found to my surprise that in MS C# 1.1 (VS.2003) you can write code like
double Large = 18446744073709551615;
This is quite a bit bigger than ulong.MaxValue - in fact, it's ulong.MaxValue * 2 + 1. I'm curious - could someone who has Mono installed check to see if the Mono C# compiler can handle this line?
--
programmer, author http://www.midnightbeach.com and father http://www.midnightbeach.com/hs
"Klaus H. Probst" wrote: Well... you're using a double there, not an int or a long.
Well, yes. Actually, I was expecting that the compiler wouldn't handle
any "double Large = <int constant>;" where <int constant> was any
greater than ulong.MaxValue. I was surprised to fin that that's not
true, that it can go all the way to "double Large =
18446744073709551615;" before demanding code like "double Large =
18446744073709551616d;".
If you try a long you'll probably get a compiler error along the lines of "can't do implicit cast of 'ulong to long'. And if you cast it you'll still get an error and a recommendation that you use unchecked code... which is not a good idea to say the least =)
Thanks, but not news, and not what I'm asking about .... I was experimenting with implicit typing of integer constants, and found to my surprise that in MS C# 1.1 (VS.2003) you can write code like
double Large = 18446744073709551615;
This is quite a bit bigger than ulong.MaxValue - in fact, it's ulong.MaxValue * 2 + 1. I'm curious - could someone who has Mono installed check to see if the Mono C# compiler can handle this line?
--
programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs
Jon Shemitz <jo*@midnightbeach.com> wrote: "Klaus H. Probst" wrote:
Well... you're using a double there, not an int or a long.
Well, yes. Actually, I was expecting that the compiler wouldn't handle any "double Large = <int constant>;" where <int constant> was any greater than ulong.MaxValue. I was surprised to fin that that's not true, that it can go all the way to "double Large = 18446744073709551615;" before demanding code like "double Large = 18446744073709551616d;".
Indeed - according to the C# spec, I that it shouldn't compile.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Jon Shemitz" <jo*@midnightbeach.com> wrote in message
news:40***************@midnightbeach.com... I was experimenting with implicit typing of integer constants, and found to my surprise that in MS C# 1.1 (VS.2003) you can write code like
double Large = 18446744073709551615;
This is quite a bit bigger than ulong.MaxValue - in fact, it's ulong.MaxValue * 2 + 1. I'm curious - could someone who has Mono installed check to see if the Mono C# compiler can handle this line?
Mono's mcs 0.29 accepts this as well, didn't check to ensure it was correct,
but it does accept it.
--
programmer, author http://www.midnightbeach.com and father http://www.midnightbeach.com/hs
"Daniel O'Connell [C# MVP]" wrote: Mono's mcs 0.29 accepts this as well, didn't check to ensure it was correct, but it does accept it.
Thanks! Didn't really want to install mono on my ancient Linux machine
just for a footnote (that might get canned anyway).
--
programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs
"Jon Shemitz" <jo*@midnightbeach.com> wrote in message
news:40***************@midnightbeach.com... "Daniel O'Connell [C# MVP]" wrote:
Mono's mcs 0.29 accepts this as well, didn't check to ensure it was
correct, but it does accept it. Thanks! Didn't really want to install mono on my ancient Linux machine just for a footnote (that might get canned anyway).
Hehe, ya, I run it on my windows machien actually; rotor, mono, and the
framework. Sometimes I have to be careful what compiler I'm actually
using, -_-. --
programmer, author http://www.midnightbeach.com and father http://www.midnightbeach.com/hs
> I was experimenting with implicit typing of integer constants, and found to my surprise that in MS C# 1.1 (VS.2003) you can write code like
double Large = 18446744073709551615;
This is quite a bit bigger than ulong.MaxValue - in fact, it's ulong.MaxValue * 2 + 1. I'm curious - could someone who has Mono installed check to see if the Mono C# compiler can handle this line?
I feel so very silly - this IS ulong.MaxValue.
I must have done a Console.WriteLine() of long.MaxValue, not
ulong.MaxValue, and copy/pasted THAT value to experiment with. Of
COURSE the ulong.MaxValue would be long.MaxValue * 2 + 1, and it makes
perfect sense that that would be the largest "integral constant".
So sorry.
--
programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nicholas |
last post by:
How can I get the largest possible value of the Integer Constants and use it
in the program for these types:
1. int
2. long
3. unsigned short
Thanks
|
by: SysSpider |
last post by:
Hi again,
This is my problem: when i try to compile the code that contains the
function below, i get this:
--
gcc:21: error: case label does not reduce to an integer constant
gcc:24: error:...
|
by: jaks.maths |
last post by:
How to convert negative integer to hexadecimal or octal number?
Ex: -568
What is the equivalent hexadecimal and octal number??
|
by: Gary Brown |
last post by:
Hi,
I have a whole bunch of integer constants that are best given in octal
(PDP-1 opcodes). It makes a huge difference in readability and authenticity
if these
can be entered in octal. I...
|
by: matevzb |
last post by:
I've ran into some fishy code that, at first glance, is buggy, but it
seems to work correctly
and none of the compilers I've tried (five so far, on various systems)
gives any warnings.
The code:...
|
by: cmdolcet69 |
last post by:
Public Shared adc_value As word_byte
Public Class byte_low_hi
Public low_byte As Byte
Public high_byte As Byte
End Class
pmsg(2) = CChar(adc_value.word16.high_byte)
|
by: Fred |
last post by:
I'm having terrible trouble trying to work out exactly which of the
promotions one reads about in old books are still present in current C -
and there seems to be a distinction between promotion...
|
by: Rex Mottram |
last post by:
Can anyone explain this?
% cat t.c
#include <stdio.h>
#define FIRST "first"
#define SECOND "second"
int
main(int argc, char *argv)
|
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= |
last post by:
Let's say we had a simple function for returning the amount of days in
a month:
unsigned DaysInMonth(unsigned const month)
{
switch (month)
{
case 8:
case 3:
case 5:
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
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...
| |