473,383 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 3788
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*******@yahoo.com> wrote in message
news:a7**************************@posting.google.c om...
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
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...
16
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:...
34
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...
2
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...
9
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> ...
6
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...
29
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
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...
17
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.