G
Guest
Is this:
A = B = C;
Any more efficient than:
A = C;
B = C;
In the compiled application?
Thanks.
J
A = B = C;
Any more efficient than:
A = C;
B = C;
In the compiled application?
Thanks.
J
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Is this:
A = B = C;
Any more efficient than:
A = C;
B = C;
In the compiled application?
Is this:
A = B = C;
Any more efficient than:
A = C;
B = C;
In the compiled application?
Thanks.
J
*Message reformatted slightly*Thanks for the responses. I'm using it to
initialize a bunch of properties, or in
some cases, clear out a bunch of preprties
in a reset function. I like the more
compact syntax and I just started wondering
if it was any more efficient, or just more
convenient.
Göran Andersson said:Most likely they will be optimised into the same code.
Even if the code will be different, it's hard to predict which code will
actually perform better. If it's compiled into two separate load-store
operations, that might actually perform better than a load-store-store
sequence, as the two operations might be performed in parallel by the
processor.
Mark Howell said:There are two problems with that format:
1) You have to know the order of evaluation.
2) You're betting that that order will never be changed.
As for readability, I feel rather the opposite, it seems a bit too terse
rather than clear.
Kevin said:There is no evaluation in the expression A = B = C; It is an assignment
expression.

The only order issue is that the value to be assigned be on the
right. The order of the other (lefthand) operands is irrelevant.
Mark said:In some cases, A = B = C better represents what I mean that putting the
assignments on separate lines. It says "I want all three of these values to
be the same." If that's only incidentally true, then I'd put them on
separate lines.
///ark
Is this:
A = B = C;
Any more efficient than:
A = C;
B = C;
In the compiled application?
Arne said:I would expect same code generated, but that is implementation
not language.
The construct is an old C'ism.
And it should not have been migrated from the 70's to
the 80's in my opinion.
Arne
Rick said:Oh, it's older than that. Saves on 80-column punch cards, you see . . .
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.