Short-circuiting in C

D

Dr Nick

Eric Sosman said:
C has no way to express "parallel threads of computation"
(except in the restrictive senses of volatile variables and
asynchronous signals).


Fine: Your compiler made promises that are not made by C and
are not expressible in C. There's nothing preventing you from
making such promises, and in the right circumstances such promises
are useful and laudable. But they're *your* promises, not C's,
and compilers other than your own are under no obligation to pay
the slightest heed to them. C has no way to tell those other
compilers about a desire for parallelism, nor any means to detect
a promise broken.


Exactly. The O.P. needs something other than C, or something
in addition to C.

To be fair, and I know I'm coming late to the party, the OP was asking
"is there a way to express what C usually does by a && b && c that
doesn't do the short-circuiting behaviour" and then explained why. That
seemed an entirely reasonable question about C. People suggested
several ways and all pointed out that this couldn't guarantee it (and
also that a really good compiler for his platform could cope with a && b
&& c in the way he wanted).
 
S

Shao Miller

To be fair, and I know I'm coming late to the party, the OP was asking
"is there a way to express what C usually does by a&& b&& c that
doesn't do the short-circuiting behaviour" and then explained why. That
seemed an entirely reasonable question about C. People suggested
several ways and all pointed out that this couldn't guarantee it (and
also that a really good compiler for his platform could cope with a&& b
&& c in the way he wanted).

"Couldn't guarantee it" <- what is "it?" Avoiding the short-circuiting
behaviour? Examples were given for constructs which evaluate all of
'a', 'b', 'c' and then choose a path based on the truth of 'a && b &&
c', even though that expression is not used in the constructs.
 
8

88888 Dihedral

Billy Maysæ–¼ 2011å¹´5月27日星期五UTC+8上åˆ2時51分20秒寫é“:
I did not, but I suspect using an & instead of an && would fail if a was
1 and b was 2. The programming guide I was using mentioned that the
short-circuiting behavior would force all the threads to serialize
rather than run in lockstep.

If the integer mutltiplication * is as fast as a jump, then
I'll write if (a*b*c) {... };//, but this is too platform dependent.
 
8

88888 Dihedral

Sorry, there is no closure assumed in C.
I am thinking in Python and Pike mostly nowadays in 201X.
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
474,078
Messages
2,570,570
Members
47,204
Latest member
MalorieSte

Latest Threads

Top