473,395 Members | 1,537 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,395 software developers and data experts.

know bug, bug, or me being stupid. Immediate cast bug..

PT
Hi, not sure if this is just me, an already known bug or what, but if anyone
can shed light on why this does what it does it would be greatly
appreciated, it seems to work as expected if you're dealing with Int32
variables rather than immediates.

public class Test
{
public void Tester( object o )
{
Console.WriteLine("not a byte");
}
public void Tester(byte o)
{
Console.WriteLine("is a byte");
}
};

Test t = new Test();
t.Tester((byte)0);
t.Tester((UInt32)0);
t.Tester((Int32)0); <--- reports "is a byte"

Regards,

Paul
Aug 1 '06 #1
3 1070
PT wrote:
Hi, not sure if this is just me, an already known bug or what, but if anyone
can shed light on why this does what it does it would be greatly
appreciated, it seems to work as expected if you're dealing with Int32
variables rather than immediates.
It's not actually a bug, although I agree it looks that way at
first.(Int32)0 is still a constant expression (of type int), and so is
implicitly convertible to byte according to the spec.

Jon

Aug 1 '06 #2
PT
Yeah, I guess that makes sense, albeit confusing if you see said code being
passed to a stream writer :) Thanks again.

Paul.

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
PT wrote:
>Hi, not sure if this is just me, an already known bug or what, but if
anyone
can shed light on why this does what it does it would be greatly
appreciated, it seems to work as expected if you're dealing with Int32
variables rather than immediates.

It's not actually a bug, although I agree it looks that way at
first.(Int32)0 is still a constant expression (of type int), and so is
implicitly convertible to byte according to the spec.

Jon

Aug 1 '06 #3
Jon Skeet [C# MVP] wrote:
PT wrote:
Hi, not sure if this is just me, an already known bug or what, but if anyone
can shed light on why this does what it does it would be greatly
appreciated, it seems to work as expected if you're dealing with Int32
variables rather than immediates.

It's not actually a bug, although I agree it looks that way at
first.(Int32)0 is still a constant expression (of type int), and so is
implicitly convertible to byte according to the spec.
<spec section 13.1.7>

An implicit constant expression conversion permits the following
conversions:
· A constant-expression (§14.16) of type int can be converted to
type sbyte, byte, short, ushort, uint, or ulong, provided the value of
the constant-expression is within the range of the destination type.

</spec>

Never would have guessed. You learn something new every day.

Michael

Aug 1 '06 #4

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

Similar topics

2
by: Lampa Dario | last post by:
Hi, where is this stupid error in this program? When I execute it, i receive a segmentation fault error. #include <stdio.h> int main(int argc, char *argv, char *env) { int i=0; int l=0; int...
2
by: Jon Davis | last post by:
How do I get the Immediate window back? It seems to be gone. Command window doesn't work. "View" menu items don't seem to show it Jon
3
by: Bill | last post by:
I am confused why I must cast an enum to a type int if I defined the enum as follows: enum COLUMNS :int { IP=0, MSG =1 } IMHO the compiler should be able to make the conversion without...
4
by: TS | last post by:
I have this simple equation that returns a boolean: if( ti.NumberIncorrect > (TotalQuestions - (TotalQuestions * FailurePercentage) )) ti.NumberIncorrect is int : 4 TotalQuestions is int :...
3
by: Rob Mayo | last post by:
This is a stupid problem to have, but here goes. I wanted to make like an Outlook-looking app. Multiple splitters, panes, etc. If I ... 1. Take a Form, add a TreeView, dock it Left. 2. Add a...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
6
by: Frank Rizzo | last post by:
I am using the Immediate Window a lot to see the progress of the application. In VS2003, if your cursor was at the very bottom, the window would scroll down whenever something new showed up. If...
1
by: lakon15 | last post by:
Dear all, I'll try to convert from SQL server Store Procedure to DB2 Store Procedure. I've make SP under DB2 like this CREATE PROCEDURE GetSearchedRecords (pKeyWords VARCHAR(1000), ...
3
by: Rahul Babbar | last post by:
Hi, I have the following doubt. Suppose I use the execute immediate statement and the statement to be executed is a Select statement from the sysibm.sysdummy1 table which will always return...
10
by: Chris Becke | last post by:
In C and in older C++ compilers, you could write code like this void a(void** pp); // declare a function that takes a pointer to a pointer-to-void. struct I {}; // some struct. I *i1,**i2; //...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.