Hi,
This is a very basic question.
What will happen if there is a statement with a relational operator
outside while, for, or if conditions?
Something like this...
..
..
..
state == 2;
..
..
Will the statement be ignored (or as good as ignored) all the times?
Thanks,
Deepak 11 1464
Janus said:
Hi,
This is a very basic question.
What will happen if there is a statement with a relational operator
outside while, for, or if conditions?
Something like this...
.
.
.
state == 2;
.
.
Will the statement be ignored (or as good as ignored) all the times?
In this case, assuming 'state' is what it appears to be, the compiler is
very likely to ignore it completely, although a good compiler will probably
diagnose it - "code has no effect" or something along those lines.
But if you had:
state == function();
that would be a different matter, since function() may have side effects.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Janus wrote On 08/09/06 12:18,:
Hi,
This is a very basic question.
What will happen if there is a statement with a relational operator
outside while, for, or if conditions?
Something like this...
.
.
.
state == 2;
.
.
Will the statement be ignored (or as good as ignored) all the times?
The expression is evaluated, and the result of the
evaluation is discarded. The compiler may (or may not)
"notice" that the evaluation makes no difference to the
behavior of the program, and then decide to eliminate it.
If the evaluation has no effect, there is no way for the
program to discover whether it was or was not performed.
There's nothing special about the relational operators
in this regard. Here are some other expressions to ponder:
x + y;
c ? x : y;
x;
.... and, of course
state++ == 2;
-- Er*********@sun .com
Thanks a lot for the reply.
I was using an enum value on Right hand side, and the == was a typo
actually and was not solving my issue. So I was just curious.
Thanks once again,
Deepak
Eric Sosman wrote:
Janus wrote On 08/09/06 12:18,:
Hi,
This is a very basic question.
What will happen if there is a statement with a relational operator
outside while, for, or if conditions?
Something like this...
.
.
.
state == 2;
.
.
Will the statement be ignored (or as good as ignored) all the times?
The expression is evaluated, and the result of the
evaluation is discarded. The compiler may (or may not)
"notice" that the evaluation makes no difference to the
behavior of the program, and then decide to eliminate it.
If the evaluation has no effect, there is no way for the
program to discover whether it was or was not performed.
There's nothing special about the relational operators
in this regard. Here are some other expressions to ponder:
x + y;
c ? x : y;
x;
... and, of course
state++ == 2;
-- Er*********@sun .com
Janus (in 11************* *********@m79g2 00...legr oups.com) said:
| This is a very basic question.
|
| What will happen if there is a statement with a relational operator
| outside while, for, or if conditions?
|
| Will the statement be ignored (or as good as ignored) all the times?
The operator will work as expected. One of my favorite examples:
int sign;
:
sign = (x 0) - (x < 0);
sets the variable sign to 1, 0, or -1 if x is positive, zero, or
negative.
--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA http://www.iedu.com/DeSoto
In article <11************ **********@m79g 2000cwm.googleg roups.com>,
Janus <de************ ****@gmail.comw rote:
>What will happen if there is a statement with a relational operator outside while, for, or if conditions?
Something like this... . state == 2;
The important thing to realise - as you seem to have done - is
that == is just an operator, so this statement is not really any
different from
3+4;
Not all languages work like this. In some languages comparisons are
(or were, I don't think many modern languages do it) part of the
syntax of conditionals.
-- Richard
Eric Sosman wrote:
>
Janus wrote On 08/09/06 12:18,:
[...]
state == 2;
[...]
There's nothing special about the relational operators
in this regard. Here are some other expressions to ponder:
x + y;
c ? x : y;
x;
... and, of course
state++ == 2;
I assume that:
state++ == state++;
is still UB, even though there's no assignment?
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>
Kenneth Brody wrote On 08/10/06 11:32,:
>
I assume that:
state++ == state++;
is still UB, even though there's no assignment?
Right: two modifications to the same object without
an intervening sequence point -unbehaved definior.
-- Er*********@sun .com
Kenneth Brody said:
<snip>
I assume that:
state++ == state++;
is still UB, even though there's no assignment?
Yes, it's still UB, because:
"Between the previous and next sequence point an object shall have
its stored value modified at most once by the evaluation of an
expression. Furthermore, the prior value shall be accessed only to
determine the value to be stored."
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
"Eric Sosman" <Er*********@su n.comwrote in message
news:1155141422 .263649@news1nw k...
x + y;
c ? x : y;
x;
... and, of course
state++ == 2;
what about in this case? Is the compiler allowed to not execute the pointer
dereference?
int main(void) {
char *p = some_address();
*p == 3;
return 0;
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Thomas |
last post by:
Hi everybody!
I have the following code:
---snip---
class BaseRecord
{
protected:
struct tFieldLenData
{
|
by: Steven T. Hatton |
last post by:
It blows up on a 9 dimensional space, but I'm pretty sure that's due to the
size of size_t.
--- begin: DataGeneration_Test ---
Tensor<T 3, 3>
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27
TensorIndices<3, 3>
::ORDER : 3
::RANK : 3
::SIZE : 27
|
by: raju |
last post by:
hi
can we compare two integers without using relational operators (== != <
<= > >=)
thanks
rajesh s
|
by: Locia |
last post by:
I would like compare all type.
I try with this function but I get System.NullReference.Exception if
pass in Compare function two int type.
Why relational operation isn't defined for basic type as int?
How can I do?
private bool Compare(Object leftOperand,String op,Object rightOperand)
{
if (op.Equals(">"))
|
by: gupta.keshav |
last post by:
Hi,
I want to know the trick of implementing condition operator or
(if()... else...).
Symbols to use:
~, !, ^,&, +, |, <<, >>.
NOt to use:
if statement,
loops,
| |
by: Pradeep |
last post by:
Hello,
I need to take a set of input tables and create an XML output file. The
format of the XML output must be user-definable and must be intuitive
enough for non-techies to use.
input table(s) + SomeSchemaDefinition ==XML file
I have seen examples of XML file generation with fixed scope. For
example, if input table (called customer) is as follows:
|
by: Noah Roberts |
last post by:
template < typename T >
std::istream & operator >(std::istream & in, std::pair<T,T& p)
{
in >p.first >p.second;
return in;
}
....
std::istream_iterator< std::pair<size_type, size_type
|
by: AliceB.Toklas |
last post by:
In my Absolute Beginner's Guide to C book by Greg Perry
where it is instruction how relational operators work it gives the
following example:
int i = 5;
so the following statement is true:
int i == 1
|
by: ujjc001 |
last post by:
Here's one for ya. I want to create a relational operator from a
string object, i.e. I want to somehow be able to say:
string opString = ">=";
int i1 = "20";
int i2 = "10";
if (i1 somemethodhere(opString) i2) {
//do the true here
}
else {
|
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...
|
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...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |