473,396 Members | 1,970 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,396 software developers and data experts.

Returning an assignment?

Given this line:
if (!constmap_init(&maprh, pm.s, pm.len, 0)) return flagrh = -1;

What happens if constmap(..) returns 0? flagrh is a static global, and
could have any value in it. Is flagrh assigned -1 then returned, or is it
the other order, or possibly even undefined behavior?

Only reason I ask is i'm tracking down a bug and am unable to reproduce it
on my system.

Thanks

--
Sig
Fri Nov 21 12:37:02 EST 2003

Nov 13 '05 #1
4 1297
signuts wrote:
Given this line:

if (!constmap_init(&maprh, pm.s, pm.len, 0)) return flagrh = -1;

What happens if constmap(..) returns 0? flagrh is a static global, and
could have any value in it. Is flagrh assigned -1 then returned, or is it
the other order, or possibly even undefined behavior?


I'll give it my best shot.

Your code is equivalent to:

if (constmap_init(&maprh, pm.s, pm.len, 0) == 0)
{
flagrh = -1;
return -1;
}

Nov 13 '05 #2

"signuts" <ex****@triton.net> wrote in message
news:pa****************************@triton.net...
| if (!constmap_init(&maprh, pm.s, pm.len, 0)) return flagrh = -1;
|
| What happens if constmap(..) returns 0? flagrh is a static global, and
| could have any value in it. Is flagrh assigned -1 then returned, or is it
| the other order, or possibly even undefined behavior?

When executing:
return flagrh = -1
-1 is first assigned to flagrh. Then the value of flagrh is returned.
The behavior is well-defined.

| Only reason I ask is i'm tracking down a bug and am
| unable to reproduce it on my system.

The only thing I would check is the type of flagrh.
Say for example that it is defined as:
static unsigned char flagrh;
the return value might not be -1.

Other than that, I see nothing wrong in this one line...

hth -Ivan
--
http://ivan.vecerina.com
Nov 13 '05 #3
Nudge wrote:

signuts wrote:
Given this line:

if (!constmap_init(&maprh, pm.s, pm.len, 0)) return flagrh = -1;

What happens if constmap(..) returns 0? flagrh is a static global, and
could have any value in it. Is flagrh assigned -1 then returned, or is it
the other order, or possibly even undefined behavior?


I'll give it my best shot.

Your code is equivalent to:

if (constmap_init(&maprh, pm.s, pm.len, 0) == 0)
{
flagrh = -1;
return -1;
}


Almost right, but not quite. For example, consider

int foo(void) {
static unsigned char flagrh;
if (that_big_mess)
return flagrh = -1;
...
}

The returned value is UCHAR_MAX, not -1: a positive
value rather than a negative.

To the O.P.: The construct you see is perfectly
well-defined and perfectly legal. However, you might
want to check whether the `=' might be a misspelling
of `=='; it's just possible that the intent is not to
do an assign-and-return but a compare-and-return.

--
Er*********@sun.com
Nov 13 '05 #4
On Fri, 21 Nov 2003 12:39:01 -0500, signuts <ex****@triton.net> wrote:
Given this line:
if (!constmap_init(&maprh, pm.s, pm.len, 0)) return flagrh = -1;

What happens if constmap(..) returns 0? flagrh is a static global, and
could have any value in it. Is flagrh assigned -1 then returned, or is it
the other order, or possibly even undefined behavior?
If constmap returns 0, the if evaluates to true. The return statement
is executed. flagrh is first assigned the appropriate value of -1 (it
depends on type of flagrh (integer/floating, signed/unsigned, etc).
Then the new value in flagrh is converted to the return type and sent
back to the calling function.

Only reason I ask is i'm tracking down a bug and am unable to reproduce it
on my system.

Thanks


<<Remove the del for email>>
Nov 13 '05 #5

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

Similar topics

9
by: mjm | last post by:
Folks, Stroustrup indicates that returning by value can be faster than returning by reference but gives no details as to the size of the returned object up to which this holds. My question is...
6
by: JKop | last post by:
unsigned int CheesePlain(void) { unsigned int const chalk = 42; return chalk; } unsigned int& CheeseRef(void) {
12
by: Olumide | last post by:
I'm studying Nigel Chapman's Late Night Guide to C++ which I think is an absolutely fantastic book; however on page 175 (topic: operator overlaoding), there the following code snippet: inline...
6
by: Affan Syed | last post by:
Hi, first let me apologize before hand for not knowing this trivial issue and my inability to find it after searching on the web for an answer to what seems to be starightforward. I have used...
8
by: Derek | last post by:
Some authors advocate returning const objects: const Point operator+(const Point&, const Point&); ^^^^^ Returning a const object prevents some bad code from compiling: Point a, b, c; (a +...
2
by: matthias_k | last post by:
Hello, I'm wondering if returning const references to a class member is generally faster than returning a copy of the object. Consider this code: class A { std::string data; public:
25
by: Victor Bazarov | last post by:
In the project I'm maintaining I've seen two distinct techniques used for returning an object from a function. One is AType function(AType const& arg) { AType retval(arg); // or default...
9
by: Jan-Henrik Grobe | last post by:
Hallo, I am searching for helpü with non-pod objects. I have a class X which contains an object y of class Y as a member. This object is non-pod. Now I have an object x from class X and want to...
2
by: divya_rathore_ | last post by:
Dear All, Assuming that I have an object of a templated class of Linked List: LinkedList<int> IntList which adds entries using a member function like this: void AppendEntry(T& entry) and...
9
by: kiran.agashe | last post by:
Hi, Please refer program below: #include <string> #include <cstdio> using namespace std; const char* f(); main() {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
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,...
0
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,...
0
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...
0
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...

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.