473,670 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

short circuited expressions...

Just wondering, is it portable to write:

something* pSomething = getSomething();

if( pSomething && pSomething->stuff() ) {

....

}

I'm not sure if the condition statement is always shortcircuited for
every implementation of C++?

TIA
Jul 19 '05 #1
3 3805
Steven Wong escribió:
I'm not sure if the condition statement is always shortcircuited for
every implementation of C++?


It is. Your C++ manual don't say that? Find another.

Regards.
Jul 19 '05 #2

"Steven Wong" <gn*******@yaho o.com> wrote in message
news:a7******** *************** ***@posting.goo gle.com...
Just wondering, is it portable to write:

something* pSomething = getSomething();

if( pSomething && pSomething->stuff() ) {

...

}

I'm not sure if the condition statement is always shortcircuited for
every implementation of C++?


The language standard dicates that it must. However, there's
no possible way it can actually enforce this rule. An implementation
that does not obey it is not conforming, and imo should not be used.

-Mike
Jul 19 '05 #3
In article <a7************ **************@ posting.google. com>, gndm_2001
@yahoo.com says...
Just wondering, is it portable to write:

something* pSomething = getSomething();

if( pSomething && pSomething->stuff() ) {

...

}

I'm not sure if the condition statement is always shortcircuited for
every implementation of C++?


Yes it is, UNLESS you've overloaded operator&& for the types involved.

If you have something that doesn't short-circuit evaluations like this,
it's not C++ and not really even much like C++ (or C) either -- if I'm
not mistaken, short circuit evaluation has been been part of C since
before the beginning (i.e. back at least as far as B, and quite possibly
to BCPL or even CPL).

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #4

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

Similar topics

7
1790
by: Philipp | last post by:
Hello I'm working on a piece of code which I did not write and it has variables defined as: unsigned short i:13; unsigned short j:13; unsigned short k:3; As I understand the code, this means that i is reduced to being coded on 13 bits (same for j) and k is reduced to 3 bits.
16
2076
by: Justin Hoffman | last post by:
This is a question concerning query optimisation. Sorry if it's a bit long, but thanks to anyone who has the patience to help - This is my first post here... If I have two tables: 'tblContact' and 'tblCategory' where categories are like: Code Name 010101 Short 010102 Fat
34
16665
by: Andy | last post by:
Hi, Are 1 through 4 defined behaviors in C? unsigned short i; unsigned long li; /* 32-bit wide */ 1. i = 65535 + 3; 2. i = 1 - 3; 3. li = (unsigned long)0xFFFFFFFF + 3; 4. li = 1 - 3;
2
4120
by: webposter | last post by:
Hi, I am looking for information on a data structure (and associated algorithm) to do short-circuit evaluation of boolean expressions and haven't found a single one even after googing for two days! Can anyone point me to good resources (or implementations) that do this. Basically is there any way to optimize a boolean expression expressed in RPN (reverse polish notation)? I want to implement the algorithm/data structure in C. If you...
9
1753
by: Keith | last post by:
The bits get twiddled every now and then. Using gcc 3.2 and 3.4. To build: cc -o test test.c -lm ---------------- 8< test.c ------------------------ #include <stdio.h> #include <math.h> double func(double);
6
1321
by: Raymond Lewallen | last post by:
I understand the differences between And and AndAlso and the differences between Or and OrElse. Under what circumstance would you NOT use short-circuiting when evaluating expressions? It seems to me that short-circuiting should be the preference, but certainly there is a reason, other than backward-compatibility, that you would use And and Or as opposed to AndAlso and OrElse. Thank you for any explanation, Raymond Lewallen
29
2664
by: john | last post by:
I read in the first question in the FAQ that both short and int are guaranteed to be able to hold values up to 32,767. Then why would one use an int instead of a short if short takes less space?
9
16817
by: Alberto Cardoso | last post by:
Is there a direct way to convert a short array to a byte array? I dont to use a for and cast every short to a byte. I want something like the BitConverter class that accpets a short array as argument. Bitconverter.GetBytes( short ); -- Alberto Cardoso
17
1926
by: somenath | last post by:
Hi All, I have one question regarding the bellow mentioned code #include<stdio.h> int main(void) { int x = 0; int y = 0;
0
8471
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
8903
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...
1
8592
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,...
0
7421
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
5686
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
4213
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...
1
2802
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
2
2044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1795
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.