Hi,
I wondering if there is a standard specification for evalutation of
logical expressions. For instance:
if (p != NULL && strlen(p) x )
do_something();
If p is actually NULL, should this code (built with a generic
compiler) crash?
Considering that the first element is FALSE, evalutation of strlen()
is useless, so it (theoretically) should be skipped...
My compiler (gcc) works as I expected, is it a standard behaviour?
Thanks,
s. 3 1875
gallows wrote:
>
Hi,
I wondering if there is a standard specification for evalutation of
logical expressions.
N869
6.5.13 Logical AND operator
[#4] Unlike the bitwise binary & operator, the && operator
guarantees left-to-right evaluation; there is a sequence
point after the evaluation of the first operand. If the
first operand compares equal to 0, the second operand is not
evaluated.
For instance:
if (p != NULL && strlen(p) x )
do_something();
If p is actually NULL, should this code (built with a generic
compiler) crash?
No.
Considering that the first element is FALSE, evalutation of strlen()
is useless, so it (theoretically) should be skipped...
My compiler (gcc) works as I expected, is it a standard behaviour?
Yes.
--
pete
gallows <g4ll...@gmail.comwrote:
Hi,
I wondering if there is a standard specification for evalutation of
logical expressions. For instance:
if (p != NULL && strlen(p) x )
do_something();
This is a FAQ... http://c-faq.com/expr/shortcircuit.html
--
Peter
On 5 Nov, 02:52, Peter Nilsson <ai...@acay.com.auwrote:
gallows <g4ll...@gmail.comwrote:
Hi,
I wondering if there is a standard specification for evalutation of
logical expressions. For instance:
if (p != NULL && strlen(p) x )
do_something();
This is a FAQ...
http://c-faq.com/expr/shortcircuit.html
--
Peter
Ouch, I'm sorry.
Thanks! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andrew Durdin |
last post by:
In Python, you can override the behaviour of most operators for a
class, by defining __add__, __gt__, and the other special object
methods.
I noticed that, although there are special methods for...
|
by: der |
last post by:
Hello all,
I've a question about order of evaluations in expressions that have && and
|| operators in them.
The question is: will the evalution go left-to-right, no matter what -- even
if the...
|
by: Richard |
last post by:
Boy, I'll sure bet this is a FAQ.
Many years ago, my "runtime behavior of programming languages" prof
absolutely guaranteed that C parameters are evaluated left-to-right.
He was a bright guy...
|
by: Ravi Uday |
last post by:
Hi,
-I have some confusion on the order in which the operators are evaluated.
A statement such as 7/9*9+6-4 is evaluated in which order ?
-Which of the following is evaluated first:
a) &&
b)...
|
by: Christopher Benson-Manica |
last post by:
Of course one can get the effect with appropriate use of existing
operators, but a ^^ operator would make for nice symmetry (as well as
useful to me in something I'm working on). Am I the only one...
|
by: ThunderMusic |
last post by:
Hi,
I have a value that contains flags that I must get using a bitmask. I tryied
with the && operator, but the compiler outputs this error :
Operator '&&' cannot be applied to operands of type...
|
by: andreas ames |
last post by:
Hi all,
recently I came across a line of code like the following:
if seq.erase(seq.begin(), seq.end()) != seq.end()
/* ... */
It made me wonder if this is just bogus or if it even can...
|
by: TheLostLeaf |
last post by:
Hi,
Does anyone know if these 2 code segments would operate the same way.
for instance if the first condition fails does it bother to check the
second?
if (MyList.Count 0 && CheckDate) {
|
by: Rasjid |
last post by:
Hello,
I have just joined and this is my first post.
I have never been able to resolve the issue of order of evaluation in
C/C++ and the related issue of precedence of operators, use of...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |