By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 802 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Returning an assignment?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.