473,811 Members | 2,859 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Did you know?

Did you know that the following if statement is semantically
right, but could logically be wrong?

if ( i = 2 )
{
/* do something */
}

Tip:

The compiler may only produce a waring: "Possibly incorrect
assignment", but we may ignore it. To avoid such a mistake,
just reverse the two identifiers.

if ( 2 == i )
{
/* do something */
}

If '==' is replaced by an '=', the compiler will give an error
saying "Lvalue required".

--
"When you will be pleased to dine, Mr. Homles?" asked Mrs Hudson,
the landlady, curiosly.
"At seven thirty, the day after tomorrow." said he invovled in his work.

Nov 13 '05 #1
47 2704
Vijay Kumar R Zanvar <vi*****@hotmai l.com> scribbled the following:
Did you know that the following if statement is semantically
right, but could logically be wrong? if ( i = 2 )
{
/* do something */
} Tip: The compiler may only produce a waring: "Possibly incorrect
assignment", but we may ignore it. To avoid such a mistake,
just reverse the two identifiers. if ( 2 == i )
{
/* do something */
} If '==' is replaced by an '=', the compiler will give an error
saying "Lvalue required".


Yes, we did know all this. But thanks for letting us know anyway.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"I am looking for myself. Have you seen me somewhere?"
- Anon
Nov 13 '05 #2

"Joona I Palaste" <pa*****@cc.hel sinki.fi> wrote in message
news:bl******** **@oravannahka. helsinki.fi...
Vijay Kumar R Zanvar <vi*****@hotmai l.com> scribbled the following:


^^^^^^^^

Did I scribble?

Did you know that the following if statement is semantically
right, but could logically be wrong?
[...]
If '==' is replaced by an '=', the compiler will give an error
saying "Lvalue required".


Yes, we did know all this. But thanks for letting us know anyway.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ---------------------------\


I suppose it would be fun working with you, Mr. Palaste. You must be a
comedian!!

--
"We approached the case, you remember Watson," said
Mr. Homles, "with an absolutely blank mind, which is
always an advantage."

Nov 13 '05 #3
In article <bl************ @ID-203837.news.uni-berlin.de>, Vijay Kumar R Zanvar wrote:
Did you know that the following if statement is semantically
right, but could logically be wrong?

if ( i = 2 )
{
/* do something */
}

Yes, it's a well known fact and it's in the FAQ:

http://www.eskimo.com/~scs/C-faq/q17.4.html
--
Andreas Kähäri
Nov 13 '05 #4
Vijay Kumar R Zanvar wrote:
if ( 2 == i )
{
/* do something */
}


What if 2 != i but i == 2, ever thought of that?

BTW, did you know that the above code doesn't do anything even if 2 ==
i? I wonder what happens if i == 2 though...

NR

Nov 13 '05 #5
In article <bl************ @ID-203837.news.uni-berlin.de>,
Vijay Kumar R Zanvar <vi*****@hotmai l.com> wrote:
Did you know that the following if statement is semantically
right, but could logically be wrong?

if ( i = 2 )
{
/* do something */
}


Did you know that the following if statement is semantically
right, but could logically be wrong?

if ( i = k )
{
/* do something */
}

--
Göran Larsson http://www.mitt-eget.com/
Nov 13 '05 #6

"Noah Roberts" <nr******@donte mailme.com> schrieb im Newsbeitrag
news:bl******** **@quark.scn.ra in.com...
Vijay Kumar R Zanvar wrote:
if ( 2 == i )
{
/* do something */
}


What if 2 != i but i == 2, ever thought of that?

BTW, did you know that the above code doesn't do anything even if 2 ==
i? I wonder what happens if i == 2 though...


What, if you replace "==" with "is equal to" as well as "!=" with "is
unequal to" and "i" with "the value contained in a variable named i" ?
Robert
Nov 13 '05 #7
On Mon, 29 Sep 2003 08:30:12 GMT, ho*@invalid.inv alid (Goran
Larsson) wrote:
Did you know that the following if statement is semantically
right, but could logically be wrong?

if ( i = k )
{
/* do something */
}


On second thoughts it could be correct. If you want the loop
to execute with i assigned to the value of k only when k is
not zero you might as well use that form.

Sorter than:
if (k!=0)
{
i=k;
/* do everything ;)*/
}
--
main(){char s[40]="sbwjAeftqbnnf e/dpn!ps!CSbwjACj hgppu/dpn";
int i;for(i=0;i<39; putchar(s[i++]-1));return 0;}
Nov 13 '05 #8
Noah Roberts wrote:
Vijay Kumar R Zanvar wrote:
if ( 2 == i )
{
/* do something */
}


What if 2 != i but i == 2, ever thought of that?


Well, ...

#define i i, 2

Jirka

Nov 13 '05 #9


Vijay Kumar R Zanvar wrote:
"Joona I Palaste" <pa*****@cc.hel sinki.fi> wrote in message
news:bl******** **@oravannahka. helsinki.fi...
Vijay Kumar R Zanvar <vi*****@hotmai l.com> scribbled the following:

^^^^^^^^

Did I scribble?
Did you know that the following if statement is semantically
right, but could logically be wrong?

[...]

If '==' is replaced by an '=', the compiler will give an error
saying "Lvalue required".


Yes, we did know all this. But thanks for letting us know anyway.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ---------------------------\

I suppose it would be fun working with you, Mr. Palaste. You must be a
comedian!!


Perhaps dry humor given the fact that everyone should know
this if they read the FAG.
See question 17.4
http://www.eskimo.com/~scs/C-faq/q17.4.html

Nov 13 '05 #10

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

Similar topics

3
3059
by: Robert | last post by:
Python doesn't know the class of a method when container not direct class attribute: >>> class X: .... def f():pass .... g=f .... l= .... >>> X.g <unbound method X.f>
5
2323
by: Michele | last post by:
What does the CIO need to know about Sequel Server administration?
20
2280
by: Simon Harvey | last post by:
Festive greetings fellow programmers! I've been programming now for about 4, maybe 5 years now. 4 of those years were at university so and I havent had much work experience of making real world applications (although I trying to make some now). There is still a lot I don't know when it comes to making programs. I know all the theory, but not how (and why) certain things are done in real world projects. My current ponderings are about...
4
1848
by: Support | last post by:
Hi, I want to know if I have changed a few records in my database using update / insert / delete methods, how can i later know which rows have been changed or modified ? I know the ExecuteNonQuery method which can give me the "number" of modified rows, but which rows are changed how do I know ? Any ideas ?
14
2373
by: J. Makela | last post by:
Hallo. This should be a pretty entertaining question for you *real* javascript writers.. I, being the lowly photoshop guy at an ad agency made the mistake of actually saying "HTML" in a conversation once.. and now I have been tasked with building a big website with LOTS of fancy javascripting. Image rollovers mostly. Only problem is that I don't really know how to do it. Of course, that's of no consequence so I have to do it anyway....
41
6098
by: Nitin Bhardwaj | last post by:
Hi all, I wanted to know whether the stack in a C program is growing upwards or downwards.So I wrote a little code to see that.Please guide me as to whether this code is correct in telling this ? #include <stdio.h> int main(void) {
37
4012
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 a function
102
5177
by: BoogieWithStu22 | last post by:
I am running into a problem with a web page I have created when viewing it in IE6 on some machines. The page has a database lookup. The user enters an account name or number and clicks a lookup button. This hits an AS400 database looks for matches and returns a dataset that is used to populate a datagrid. The user then selects one of the entries from the list, this entry is used to populate a couple of textboxes on the page and a couple...
3
2256
markmcgookin
by: markmcgookin | last post by:
Hi Folks, I have a VB app, and I have been working at it for a while, and I am now at the stage where I want to create a search function. Now don't be scared! It is in the .Net compact framework, and uses SQL Server CE as the database (This seems to scare off people trying to help! lol) but the connection and reading of data etc is all handled, and I think it is going to be a "relatively" simple function. My database has a number of fields...
5
1669
by: garks | last post by:
Is there any way to know the computer is connected to a router? I know using WebRequest is one of the method, but WebRequest need router's URL , username and password. I don't know those information. Is there any other way to know the existence of router? Thanks.
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10379
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
10124
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
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...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
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...
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
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.