473,654 Members | 3,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

shouldn't if (this!=null) generate a warning?

Shouldn't if (this!=null) generate a compiler warning?

in fact, it does not.
May 26 '06 #1
16 2340

cody wrote:
Shouldn't if (this!=null) generate a compiler warning?


What warning would you like to see?

--
Larry Lard
Replies to group please

May 26 '06 #2
"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** *************@i 39g2000cwa.goog legroups.com...
cody wrote:
Shouldn't if (this!=null) generate a compiler warning?


What warning would you like to see?


I see what the OP is driving at - sort of like asking Descartes if it's
possible to think you don't exist... :-)
May 26 '06 #3

Mark Rae wrote:
"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** *************@i 39g2000cwa.goog legroups.com...
cody wrote:
Shouldn't if (this!=null) generate a compiler warning?


What warning would you like to see?


I see what the OP is driving at - sort of like asking Descartes if it's
possible to think you don't exist... :-)


I see what they're driving at too, and I'm trying to be Socratic :)

--
Larry Lard
Replies to group please

May 26 '06 #4

"cody" <de********@gmx .de> wrote in message
news:uS******** ******@TK2MSFTN GP05.phx.gbl...
Shouldn't if (this!=null) generate a compiler warning?

in fact, it does not.

Maybe we need a "something" to go along with "null", then we could just do
if (this == something)

:-)
May 26 '06 #5
the same warning that is generated for other expressions which the compiler
determines to always be true or to alway be false.
for example an expression like "if (this is string)" will generate a warning
(if the class is not system.string or course).

--

"Larry Lard" <la*******@hotm ail.com> schrieb im Newsbeitrag
news:11******** *************@i 39g2000cwa.goog legroups.com...

cody wrote:
Shouldn't if (this!=null) generate a compiler warning?


What warning would you like to see?

--
Larry Lard
Replies to group please

May 26 '06 #6
"james" <ja***@com.co m> wrote in message
news:44******** **************@ news.zen.co.uk. ..
Maybe we need a "something" to go along with "null", then we could just do
if (this == something)


Ah yes, but just because something isn't nothing doesn't imply that it is
something...

You know what they say: "you can take a horse to water but a pencil must be
lead"

And, for the extremely politically incorrect among us, "one in Kate Bush is
worth ten in the hand..."
May 26 '06 #7
>the same warning that is generated for other expressions which the compiler
determines to always be true or to alway be false.


But in this case the condition can evaluate to false. While you're not
allowed to do it in C#, the CLR and other languages let you call
instance methods on a null reference.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 26 '06 #8
Great. So we would always have to put if (this!=null) throw new
ArgumentNullExc eption(); in every method just to make sure :-)

"Mattias Sjögren" <ma************ ********@mvps.o rg> schrieb im Newsbeitrag
news:uM******** ******@TK2MSFTN GP05.phx.gbl...
the same warning that is generated for other expressions which the
compiler
determines to always be true or to alway be false.


But in this case the condition can evaluate to false. While you're not
allowed to do it in C#, the CLR and other languages let you call
instance methods on a null reference.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

May 27 '06 #9
Mattias Sjögren <ma************ ********@mvps.o rg> wrote in
news:uM******** ******@TK2MSFTN GP05.phx.gbl:
the same warning that is generated for other expressions which the
compiler determines to always be true or to alway be false.


But in this case the condition can evaluate to false. While you're not
allowed to do it in C#, the CLR and other languages let you call
instance methods on a null reference.
Mattias


But we're discussing the CSharp compiler...
May 27 '06 #10

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

Similar topics

1
7618
by: Prakash | last post by:
Hi, I want to generate the JDK API using Javadoc. I have installed java 1.4.2 in WINDOWS. Since i don't have frequent access to the Net, i want to generate the Java API Help using javadoc.But I was unsuccessful in that. Can u give me the exact command for doing so? I had tired:
43
2705
by: Anitha | last post by:
Hi I observed something while coding the other day: if I declare a character array as char s, and try to use it as any other character array..it works perfectly fine most of the times. It holds strings of any length. I guess what is happening here is that this array initially holds only '\0' and hence is of length 1. But sometimes, when I tried to write some functions and do some
29
2509
by: junky_fellow | last post by:
Consider the following piece of code: struct junk { int i_val; int i_val1; char c_val; }; int main(void) {
40
7857
by: Dave Hansen | last post by:
Please note crosspost. Often when writing code requiring function pointers, it is necessary to write functions that ignore their formal parameters. For example, a state machine function might take a status input, but a certain error-handling state might ignore it: typedef void (*State_Fn)(uint8_t); void error_state(uint8_t status)
1
6396
by: billa1972 | last post by:
Hi, I am trying to hook into Yellow Freight's rating webservice. Below is the wsdl. When i try and create a proxy file with wsdl.exe i get the following errors, see below. Also, when i reference this wsdl in .NET it seems to do it fine, yet there are no objects to reference except RateQuoteBeanService. In the WSDL it looks like there should be getRateQuote, and QUOTEREQUEST, etc.
5
5081
by: Peter Ritchie [C# MVP] | last post by:
I've purposely been ignoring a CA2122 warning in some C++ interop code I've been working on for quite some time. I've just recently had the cycles to investigate the warning. The warning message is as follows Warning CA2122 : Microsoft.Security : MyClass.Method():Void calls into Marshal.GetExceptionPointers():IntPtr which has a LinkDemand. By making this call, Marshal.GetExceptionPointers():IntPtr is indirectly exposed to user code....
2
2864
by: BSeab1024SE | last post by:
In MS Visual C++ some code I wrote generated the warning "conversion from 'int' to 'const float', possible loss of data." In the process of trying to determine if I could rewrite the code to eliminate the warning I noticed that the following code did not generate any warning... int x = 1024; char y = x;
82
4595
by: robert bristow-johnson | last post by:
here is a post i put out (using Google Groups) that got dropped by google: i am using gcc as so: $ gcc -v Using built-in specs. Target: i386-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man -- infodir=/usr/share/info --enable-shared --enable-threads=posix -- enable-checking=release --with-system-zlib --enable-__cxa_atexit --
0
8814
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8706
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7304
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1592
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.