473,837 Members | 1,515 Online

# Question about the *= (and similar) operator

In the statement "a *= expression" is expression assumed to be
parenthesized ? For example if I write "a *= b+c" is this the same
as "a = a * (b+c)" or "a = a * b+c" ?

Jun 13 '06
56 4830
pete wrote:
CBFalconer wrote:
pete wrote:
James Dow Allen wrote:

I guess we should record that as an "Aye" vote.
I'm still voting "Neigh."

You have a horse voice.

You lose, so pony up.

That would be if his voice was only a little horse.

Can you write that as an e quine?

--
"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
Jun 17 '06 #51
Joe Wright wrote:
.... snip ...
Our realloc can be a misbehaving child and needs attention.
Consider..

int *ptr;
ptr = malloc(100 * sizeof *prt);
ptr = realloc(ptr, 200 * sizeof *ptr);

Assume malloc works and then realloc fails. We'll have ptr set
to NULL and no reference to the memory malloc gave us. A leak!

So you never misuse realloc in that manner. Instead:

if (tmp = realloc(ptr, 200 * sizeof *ptr)) ptr = tmp;
else announcememorys hortage();

no leak.

--
"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
Jun 17 '06 #52
CBFalconer <cb********@yah oo.com> writes:
Joe Wright wrote:

... snip ...

Our realloc can be a misbehaving child and needs attention.
Consider..

int *ptr;
ptr = malloc(100 * sizeof *prt);
ptr = realloc(ptr, 200 * sizeof *ptr);

Assume malloc works and then realloc fails. We'll have ptr set
to NULL and no reference to the memory malloc gave us. A leak!

So you never misuse realloc in that manner. Instead:

if (tmp = realloc(ptr, 200 * sizeof *ptr)) ptr = tmp;
else announcememorys hortage();

no leak.

Storing the result of realloc() in a separate variable is an excellent
habit. In practice, though, it may not turn out to be useful. It's
possible for a program to respond to a realloc() failure by falling
back to some less memory-intensive algorithm that uses the previously
allocated object (similarly for malloc() failuers), but it's more
likely to do some cleanup and bail out.

On the other hand, you might need information in the previously
allocated object to do the cleanup.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jun 17 '06 #53
CBFalconer wrote:
Joe Wright wrote:
... snip ...
Our realloc can be a misbehaving child and needs attention.
Consider..

int *ptr;
ptr = malloc(100 * sizeof *prt);
ptr = realloc(ptr, 200 * sizeof *ptr);

Assume malloc works and then realloc fails. We'll have ptr set
to NULL and no reference to the memory malloc gave us. A leak!

So you never misuse realloc in that manner. Instead:

if (tmp = realloc(ptr, 200 * sizeof *ptr)) ptr = tmp;
else announcememorys hortage();

no leak.

Yes, of course.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Jun 18 '06 #54
CBFalconer wrote:
pete wrote:
CBFalconer wrote:
pete wrote:
James Dow Allen wrote:

> I guess we should record that as an "Aye" vote.
> I'm still voting "Neigh."

You have a horse voice.

You lose, so pony up.

That would be if his voice was only a little horse.

Can you write that as an e quine?

You've really got the bit between your teeth now.
But I fear we're getting a bit far from the mane thread.

Jun 19 '06 #55
pete <pf*****@mindsp ring.com> wrote:
CBFalconer wrote:

pete wrote:
James Dow Allen wrote:

> I guess we should record that as an "Aye" vote.
> I'm still voting "Neigh."

You have a horse voice.

You lose, so pony up.

That would be if his voice was only a little horse.

Perhaps he has a little colt.

Richard
Jun 19 '06 #56
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
pete <pf*****@mindsp ring.com> wrote:
CBFalconer wrote:
>
> pete wrote:
> > James Dow Allen wrote:
> >
> >> I guess we should record that as an "Aye" vote.
> >> I'm still voting "Neigh."
> >
> > You have a horse voice.
>
> You lose, so pony up.

That would be if his voice was only a little horse.

Perhaps he has a little colt.

That would be a filly lame excuse.

--
Chris.
Jun 19 '06 #57

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