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

I have a doubt

P: n/a
hi all,

if I have:

if(A && B || C)

which operation gets executed first?
If I remeber well should be &&, am I correct?

thanks
Ivan
Dec 7 '06 #1
Share this Question
Share on Google+
122 Replies


P: n/a
ivan said:
hi all,

if I have:

if(A && B || C)

which operation gets executed first?
See pages 21 and 53 of K&R2. Page 21 for a detailed answer to your question,
and page 53 for a more generic answer.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 7 '06 #2

P: n/a
ivan wrote:
hi all,

if I have:

if(A && B || C)

which operation gets executed first?
A is evaluated first.
If I remeber well should be &&, am I correct?
Not until A is evaluated.
Dec 7 '06 #3

P: n/a

"Martin Ambuhl" <ma*****@earthlink.netha scritto nel messaggio
news:4t*************@mid.individual.net...
ivan wrote:
hi all,

if I have:

if(A && B || C)

which operation gets executed first?

A is evaluated first.
If I remeber well should be &&, am I correct?

Not until A is evaluated.
sorry but i do not have a C book at hand.

what I am saing is:

A && B || C

is the same as:

(A&&B)||C

or the same as:

A&&(B||C)
Dec 7 '06 #4

P: n/a
On Thu, 7 Dec 2006 10:36:51 +0100, "ivan" <te*****@wolfsafety.it>
wrote:
>hi all,

if I have:

if(A && B || C)

which operation gets executed first?
If I remeber well should be &&, am I correct?

thanks
Ivan
Assuming you meant by "operation" the "&&" and "||" operators, the C
answer is the "&&" operator gets evaluated first.

But that's not the right answer, because I don't know that you meant
that, and others reading your code might not know that you meant that,
or even know that's that the C answer.

The correct answer, in order to appease us all sitting here at the
round table, is that you must use parenthesis around the appropriate
pair of binary operands. Pick either (A && B) or (B || C). During the
code review we'll tell you if you're right or wrong. And most likely,
even before that, you'll know whether you're right or wrong.

C lets you get away with a lot of stuff. That doesn't mean you should
necessarily take the freedom to get away with said stuff.

Some organizations, such as MISRA (which deals in part with
safety-critical software), take such "stuff" very seriously, and
impose rules about what you can and cannot do in C. Many of the rules
are, IMHO, seriously worth considering in any type of software.

--
jay
Dec 7 '06 #5

P: n/a
ivan wrote:
>
"Martin Ambuhl" <ma*****@earthlink.netha scritto nel messaggio
news:4t*************@mid.individual.net...
>ivan wrote:
hi all,

if I have:

if(A && B || C)

which operation gets executed first?

A is evaluated first.
If I remeber well should be &&, am I correct?

Not until A is evaluated.

sorry but i do not have a C book at hand.

what I am saing is:

A && B || C

is the same as:

(A&&B)||C

or the same as:

A&&(B||C)
You're confusing order of evaluation with operand
grouping.

In both `(A && B) || C` and `A && (B || C)` the first
of the two operators to be evaluated [1] is the `&&` and the
first operand to be evaluated is `A`.

This is because && and || are Special and have defined
evaluation ordering. Most [2] of the other C operators
don't. What's more, for both && and || the right-hand
operand is evaluated only if the left-hand operand hasn't
already determined the value of the expression.

[1] Well, if by "operators" we mean "the expressions with
those operators".

[2] The comma /operator/ [3] and the ?: conditional operator
being the other two.

[3] Not the comma that separates function argument expressions.

--
Chris "Perikles triumphant" Dollin
Meaning precedes definition.

Dec 7 '06 #6

P: n/a
ivan wrote:
>
.... snip ...
>
what I am saing is:

A && B || C

is the same as:

(A&&B)||C

or the same as:

A&&(B||C)
Why bother? Simply use the explicit parenthesis.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

Dec 7 '06 #7

P: n/a
You're confusing order of evaluation with operand
grouping.

In both `(A && B) || C` and `A && (B || C)` the first
of the two operators to be evaluated [1] is the `&&` and the
first operand to be evaluated is `A`.

This is because && and || are Special and have defined
evaluation ordering. Most [2] of the other C operators
don't. What's more, for both && and || the right-hand
operand is evaluated only if the left-hand operand hasn't
already determined the value of the expression.
So if I got it right it should be:

1. in the case of (A && B) || C: if A=0 then the result is C,
2. in the case of A && (B || C): if A=0 then the result is 0.
3. in the case of A && B || C it evaluates from left to right, hence it is
the same as 1.
4. if I have A || B && C it is the same as (A || B) && C

am I correct?

thanks
ivan
Dec 7 '06 #8

P: n/a

"CBFalconer" <cb********@yahoo.comha scritto nel messaggio
news:45***************@yahoo.com...
Why bother? Simply use the explicit parenthesis.
is old code
Dec 7 '06 #9

P: n/a
ivan wrote:
>You're confusing order of evaluation with operand
grouping.

In both `(A && B) || C` and `A && (B || C)` the first
of the two operators to be evaluated [1] is the `&&` and the
first operand to be evaluated is `A`.

This is because && and || are Special and have defined
evaluation ordering. Most [2] of the other C operators
don't. What's more, for both && and || the right-hand
operand is evaluated only if the left-hand operand hasn't
already determined the value of the expression.

So if I got it right it should be:

1. in the case of (A && B) || C: if A=0 then the result is C,
2. in the case of A && (B || C): if A=0 then the result is 0.
Yes.
3. in the case of A && B || C it evaluates from left to right,
In the case of `A && B || C`, the grammar forces the grouping
`(A && B) || C`. (Note that this is /not/ "evaluates from
left to right"; in `A || B && C` the grouping is `A || (B && C)`.)
hence it is the same as 1.
Not "hence", but yes, the answer is the same as (1).
4. if I have A || B && C it is the same as (A || B) && C

am I correct?
No, as per my comments on (3). && is more binding than ||;
ie, ||-expressions can have &&-expressions as operands,
but not vice-versa unless bracketed.

I'm going to say this again: there are rules for grouping,
and there are rules for evaluation, and /they are not the
same thing/, although the evaluation rules must respect
the grouping.

--
Chris "Perikles triumphant" Dollin
"Who do you serve, and who do you trust?" /Crusade/

Dec 7 '06 #10

P: n/a

ivan wrote:
"CBFalconer" <cb********@yahoo.comha scritto nel messaggio
news:45***************@yahoo.com...
Why bother? Simply use the explicit parenthesis.

is old code
That's good. I have an old book here (Kernighan and Ritchie "The C
Programming Language" 1st edition, dated 1978), which tells me that &&
has higher priority than || so that's OK - "A && B || C" is equivalent
to "(A && B) || C". It also tells me that if "(A && B)" is true, then C
will not be evaluated.

Before putting the file back in to your repository, why not add the
parentheses so that the next time you or someone else reads the file,
they can see what that line of code means straight away?

Dec 7 '06 #11

P: n/a
Chris Dollin wrote:
ivan wrote:
>>You're confusing order of evaluation with operand
grouping.

In both `(A && B) || C` and `A && (B || C)` the first
of the two operators to be evaluated [1] is the `&&` and the
first operand to be evaluated is `A`.

This is because && and || are Special and have defined
evaluation ordering. Most [2] of the other C operators
don't. What's more, for both && and || the right-hand
operand is evaluated only if the left-hand operand hasn't
already determined the value of the expression.
So if I got it right it should be:

1. in the case of (A && B) || C: if A=0 then the result is C,
2. in the case of A && (B || C): if A=0 then the result is 0.

Yes.
Nit-picking, but the result is 0 or 1. In 1. the result
depends on evaluating C, but C=-1 will still result in
the expression evaluating to one.

--
imalone
Dec 7 '06 #12

P: n/a
ma**********@pobox.com wrote:

(WRT "A && B || C"):
Before putting the file back in to your repository, why not add the
parentheses so that the next time you or someone else reads the file,
they can see what that line of code means straight away?
Am I the only poster who abhors explicit parentheses in such simple
cases? If we are to assume that the code maintainer cannot be trusted
to know or figure out the correct order of evaluation, what argues
against such abominations as

int foo = bar + (baz*quux);

? Or, horrors,

void strcpy( char *dst, char *src ) {
while ( *(dst++) = *(src++) );
}

At some point the maintainer has to be expected to have a reasonable
knowledge of operator precedence so such ugliness can be avoided.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Dec 7 '06 #13

P: n/a
Christopher Benson-Manica wrote:
ma**********@pobox.com wrote:

(WRT "A && B || C"):
>Before putting the file back in to your repository, why not add the
parentheses so that the next time you or someone else reads the file,
they can see what that line of code means straight away?

Am I the only poster who abhors explicit parentheses in such simple
cases?
No. (It depends how complex the A/B/C expressions are, though.)
At some point the maintainer has to be expected to have a reasonable
knowledge of operator precedence so such ugliness can be avoided.
Indeed.

--
Chris "Perikles triumphant" Dollin
Meaning precedes definition.

Dec 7 '06 #14

P: n/a
Christopher Benson-Manica wrote:
Am I the only poster who abhors explicit parentheses in such simple
cases?
You may want to choose your fights more wisely. There is nothing wrong
with parens or braces, and there is nothing wrong with reliance on eval
rules. What I'm saying is, YOU are right, and whoever you are arguing
with is ALSO right. What that means is you can't win, unless you are
literally the policy maker. If it's YOUR project and YOU make the
rules, then by all means, lay down the law.


Dec 7 '06 #15

P: n/a
james of tucson wrote:
Christopher Benson-Manica wrote:
>Am I the only poster who abhors explicit parentheses in such simple
cases?

You may want to choose your fights more wisely.
He wasn't fighting: he was expressing an opinion.
There is nothing wrong with parens or braces,
In appropriate quantities.

Clutter is clutter. When the helpful-to-the-reader brackets
become troublesome, they are no longer helpful. (Opinions
about how much it takes to be clutter may reasonably vary.)
and there is nothing wrong with reliance on eval rules.
I should jolly well hope not: if one can't rely on the evaluation
rules, one is highly rotated.
What I'm saying is, YOU are right, and whoever you are arguing
with is ALSO right. What that means is you can't win, unless you are
literally the policy maker.
Or if you're not fighting.
If it's YOUR project and YOU make the
rules, then by all means, lay down the law.
--
Chris "Perikles triumphant" Dollin
Scoring, bah. If I want scoring I'll go play /Age of Steam/.

Dec 7 '06 #16

P: n/a
Chris Dollin wrote:
Christopher Benson-Manica wrote:

>>ma**********@pobox.com wrote:

(WRT "A && B || C"):

>>>Before putting the file back in to your repository, why not add the
parentheses so that the next time you or someone else reads the file,
they can see what that line of code means straight away?

Am I the only poster who abhors explicit parentheses in such simple
cases?


No. (It depends how complex the A/B/C expressions are, though.)
Which leads to another guideline; if the expression is complex enough to
require parentheses, it is too complex. Break it down into parts that
don't.

--
Ian Collins.
Dec 7 '06 #17

P: n/a

ivan wrote:
>
1. in the case of (A && B) || C: if A=0 then the result is C.
Just to make explicit what others have said, in this case, B
is not evaluated. eg:

void
eval(int A)
{
int B, C;
int val;

B = 0;
C = 2;

val = A && (B=1) || C;
printf(" A = %d\n", A);
printf(" A && (B=1) || C evaluates to: %d\n", val);
printf(" B = %d\n", B);
}
When A is non-zero, the expression B=1 is evaluated
and the side effect (assignment to B) takes place.

When A is 0, the overall expression is evaluated
and has the value 1 (not C), but B remains 0.

--
Bill Pursell

Dec 7 '06 #18

P: n/a
Christopher Benson-Manica wrote:
ma**********@pobox.com wrote:

(WRT "A && B || C"):
>Before putting the file back in to your repository, why not add the
parentheses so that the next time you or someone else reads the file,
they can see what that line of code means straight away?

Am I the only poster who abhors explicit parentheses in such simple
cases?
No, and I'd take it a step further. In most cases, if the expression is
complex enough to require explicit parentheses, then the expression is
too complex and should be broken down into it's constituent parts.

Every time I see parentheses in such a simple expression, my first
thought is: "They must be forcing some non-default grouping", when this
isn't the case then the original programmer just wasted some of my time
and energy.
If we are to assume that the code maintainer cannot be trusted
to know or figure out the correct order of evaluation, what argues
against such abominations as

int foo = bar + (baz*quux);

? Or, horrors,

void strcpy( char *dst, char *src ) {
while ( *(dst++) = *(src++) );
}

At some point the maintainer has to be expected to have a reasonable
knowledge of operator precedence so such ugliness can be avoided.
100% agreed.
--
Clark S. Cox III
cl*******@gmail.com
Dec 7 '06 #19

P: n/a
ivan wrote:
hi all,

if I have:

if(A && B || C)

which operation gets executed first?
If I remeber well should be &&, am I correct?
I have two doubts myself: Why do you post under the russian looking
name "ivan", when it is clear to everybody that you are from india, and
could you please please please tell us why people from India write "I
have a doubt" instead of "I have a question"?

Dec 7 '06 #20

P: n/a
"christian.bau" <ch***********@cbau.wanadoo.co.ukwrites:
>ivan wrote:
>hi all,

if I have:

if(A && B || C)

which operation gets executed first?
If I remeber well should be &&, am I correct?
>I have two doubts myself: Why do you post under the russian looking
name "ivan", when it is clear to everybody that you are from india, and
could you please please please tell us why people from India write "I
have a doubt" instead of "I have a question"?

Oh come on, grow up!
Why do you post using the name 'Christian', when you exhibit no ability to
be accepting and tolerant?

--
Chris.
Dec 7 '06 #21

P: n/a
christian.bau <ch***********@cbau.wanadoo.co.ukwrote:
I have two doubts myself: Why do you post under the russian looking
name "ivan", when it is clear to everybody that you are from india
Does it matter? If you chose to post as "vasily", would you expect to
have to justify that choice given that you seem to be from England?
and
could you please please please tell us why people from India write "I
have a doubt" instead of "I have a question"?
(Apologies for the line length.)

http://groups.google.com/group/comp....7ff1805959f510

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Dec 7 '06 #22

P: n/a
christian.bau wrote:
ivan wrote:
hi all,

if I have:

if(A && B || C)

which operation gets executed first?
If I remeber well should be &&, am I correct?

I have two doubts myself: Why do you post under the russian looking
name "ivan", when it is clear to everybody that you are from india,
The OP will have to supply the definitive answer but I can hazard a
guess. His first name's probably 'Navi' or beginning with the same. He
probably thought it was cool to reverse it and get a Russian sounding
name.
and
could you please please please tell us why people from India write "I
have a doubt" instead of "I have a question"?
Because, in English as it's taught here the word doubt is synonymous
with the word question.

Dec 8 '06 #23

P: n/a
Chris McDonald wrote:
Why do you post using the name 'Christian', when you exhibit no ability to
be accepting and tolerant?
Modelling himself on Richard I ?

Dec 8 '06 #24

P: n/a
Christopher Benson-Manica wrote:
ma**********@pobox.com wrote:

(WRT "A && B || C"):
>Before putting the file back in to your repository, why not add
the parentheses so that the next time you or someone else reads
the file, they can see what that line of code means straight away?

Am I the only poster who abhors explicit parentheses in such simple
cases? If we are to assume that the code maintainer cannot be
trusted to know or figure out the correct order of evaluation, what
argues against such abominations as
Because the C rules are weird and wonderful, and totally confusing
to anyone used to a rational set of rules. If you need to rely on
"precedence" beyond multiplicative, additive, logical (highest to
lowest) use explicit parentheses to ensure readability. You will
avoid much future confusion, and reduce the number of threads
similar to this one.

Even algebraic precedence is apparently unknown to the
manufacturers of most 4 function calculators.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Dec 8 '06 #25

P: n/a
CBFalconer <cb********@yahoo.comwrites:
Christopher Benson-Manica wrote:
>ma**********@pobox.com wrote:

(WRT "A && B || C"):
>>Before putting the file back in to your repository, why not add
the parentheses so that the next time you or someone else reads
the file, they can see what that line of code means straight away?

Am I the only poster who abhors explicit parentheses in such simple
cases? If we are to assume that the code maintainer cannot be
trusted to know or figure out the correct order of evaluation, what
argues against such abominations as

Because the C rules are weird and wonderful, and totally confusing
to anyone used to a rational set of rules.
They have always seemed very well thought out to me, but I understand
from other postings of yours that we will not agree on this.
If you need to rely on
"precedence" beyond multiplicative, additive, logical (highest to
lowest) use explicit parentheses to ensure readability. You will
avoid much future confusion, and reduce the number of threads
similar to this one.
You have to add more than that or you and your readers will go
bonkers. Probably at least dereference, ".", "->", cast, array
subscript, function call and assignment. I might add even more, but
then I like C's rules.

For example the perfectly reasonable:

h = h * 37UL + (unsigned char) *string++;

would be

h = (h * 37UL + ((unsigned char) *(string++)));

by your rules.

--
Ben.
Dec 8 '06 #26

P: n/a
Old Wolf wrote:
Chris McDonald wrote:
>Why do you post using the name 'Christian', when you exhibit no
ability to be accepting and tolerant?

Modelling himself on Richard I ?
The Lionheart?

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Dec 8 '06 #27

P: n/a
santosh wrote:
christian.bau wrote:
.... snip ...
>>
I have two doubts myself: Why do you post under the russian looking
name "ivan", when it is clear to everybody that you are from india,

The OP will have to supply the definitive answer but I can hazard a
guess. His first name's probably 'Navi' or beginning with the same. He
probably thought it was cool to reverse it and get a Russian sounding
name.
Maybe Ivan is an expatriate Russian, fleeing from Putins poisoners.
>and could you please please please tell us why people from India
write "I have a doubt" instead of "I have a question"?

Because, in English as it's taught here the word doubt is synonymous
with the word question.
The usage seems odd to us, but the meaning is clear. More to the
point, why do many Indians persist in using silly abbreviations
such as u, ur, etc. Did they pick it up from the kewl script
kiddies or other low lifes.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Dec 8 '06 #28

P: n/a
Ben Bacarisse wrote:
CBFalconer <cb********@yahoo.comwrites:
>Christopher Benson-Manica wrote:
>>ma**********@pobox.com wrote:

(WRT "A && B || C"):

Before putting the file back in to your repository, why not add
the parentheses so that the next time you or someone else reads
the file, they can see what that line of code means straight away?

Am I the only poster who abhors explicit parentheses in such simple
cases? If we are to assume that the code maintainer cannot be
trusted to know or figure out the correct order of evaluation, what
argues against such abominations as

Because the C rules are weird and wonderful, and totally confusing
to anyone used to a rational set of rules.

They have always seemed very well thought out to me, but I understand
from other postings of yours that we will not agree on this.
> If you need to rely on
"precedence" beyond multiplicative, additive, logical (highest to
lowest) use explicit parentheses to ensure readability. You will
avoid much future confusion, and reduce the number of threads
similar to this one.

You have to add more than that or you and your readers will go
bonkers. Probably at least dereference, ".", "->", cast, array
subscript, function call and assignment. I might add even more, but
then I like C's rules.

For example the perfectly reasonable:

h = h * 37UL + (unsigned char) *string++;

would be

h = (h * 37UL + ((unsigned char) *(string++)));

by your rules.
You have a point. I was making the implied assumption that we were
dealing with arithmetical operators.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

Dec 8 '06 #29

P: n/a
>CBFalconer <cb********@yahoo.comwrites:
>>Because the C [parsing] rules [for various operators] are weird
and wonderful, and totally confusing to anyone used to a rational
set of rules.
In article <87************@bsb.me.uk>,
Ben Bacarisse <be********@bsb.me.ukwrote:
>They have always seemed very well thought out to me, but I understand
from other postings of yours that we will not agree on this.
The main exception to this is the binding of "&" and "|". Dennis
Ritchie explained their mis-placement in a Usenet posting many years
ago. Once upon a time, C did not have "&&" and "||" operators.
Instead, if you wanted to check whether p was non-NULL before
accessing p->field, you wrote [%]:

if (p != NULL & p->field)

The compiler would figure out that you meant "&&" by seeing that
the "&" operator was placed in a boolean context -- i.e., the
test inside an if (or while loop or similar) -- and do a logical
AND instead of a bitwise AND. After experience with this, the
Bell Labs folks decided to put in a separate "&&" operator, so
that not only could you write:

if (p != NULL && p->field)

(with the obvious meaning), but you could also do:

result = p != NULL && p->field;

(with the logical AND meaning, rather than the bitwise AND you
would get with a single "&" -- remember that prototypic-C was
extremely cavalier about types, so the compiler would cheerfully
treat the pointer as an integer here).

When the operators were split, the syntax was not adjusted, leaving
the now-always-bitwise & and | operators in the "wrong" positions,
precedence/binding-wise. The result is that:

if (x & MASK == 0)

binds as:

if (x & (MASK == 0))

instead of the "more obvious":

if ((x & MASK) == 0)

because prototypic-C took this to mean:

if (x && MASK == 0)

which clearly *should* (and still does) bind as:

if (x && (MASK == 0))
-----
[%] Actually, "p && p->field" would be more likely, or perhaps
"p != 0 && p->field". Not only was the language quite casual about
interchanging integers and pointers, so were programmers, who
rather often wrote odd code like:

0770440->bar = addr;

In those days, no casts were required, and none used. :-)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Dec 8 '06 #30

P: n/a

CBFalconer wrote:
Christopher Benson-Manica wrote:
Am I the only poster who abhors explicit parentheses in such simple
cases?
No.
Because the C rules are weird and wonderful, and totally confusing
to anyone used to a rational set of rules.
Many of the unusual precedences are easy to remember
when you notice a pattern: "&" is spelled similarly to "&&",
so like the latter "&" has a low precedence. Similarly ">"
and "<" have low precedence and so do ">>" and "<<".
(Obviously the pattern doesn't follow a simple rule --
& is higher than && but << is higher than < -- but that
isn't a source of confusion.)

I also object to the idea that complex expressions should
be avoided. I frequently write complicated variants of
if (0
|| foo1 && foo2 && foo3
|| foo4 && foo5 && foo6
|| foo7 && foo8 && foo9)
launch();
Often this is the simplest most readable form of the logic.
(The leading "0 ||" may seem silly, but gives the expression
an easily-read, easily-edited pattern.)

James Dow Allen

Dec 8 '06 #31

P: n/a
CBFalconer wrote:
santosh wrote:
christian.bau wrote:
<snip>
and could you please please please tell us why people from India
write "I have a doubt" instead of "I have a question"?
Because, in English as it's taught here the word doubt is synonymous
with the word question.

The usage seems odd to us, but the meaning is clear. More to the
point, why do many Indians persist in using silly abbreviations
such as u, ur, etc. Did they pick it up from the kewl script
kiddies or other low lifes.
It's the result of the rampant use of cell phones with SMS facility.
Since each character costs a certain amount, ridiculous abbreviations
become the norm, gradually invading into email, forums and probably
even snail mail, God forbid if I know.

Cost is also, partly, the reason why the very vast majority use Google
Groups to access Usenet. Subscriptions with news providers are not
cheap, (especially if you consider that almost no Indian ISP provides
Usenet access as a part of their package), and hunting around for
public/free news servers is too much of a technical hassle.

Dec 8 '06 #32

P: n/a
James Dow Allen wrote:
>
I also object to the idea that complex expressions should
be avoided. I frequently write complicated variants of
if (0
|| foo1 && foo2 && foo3
|| foo4 && foo5 && foo6
|| foo7 && foo8 && foo9)
launch();
Often this is the simplest most readable form of the logic.
(The leading "0 ||" may seem silly, but gives the expression
an easily-read, easily-edited pattern.)
I'd prefer something like:

if( whateverTheConditionIsForLaunch() )
{
launch();
}

--
Ian Collins.
Dec 8 '06 #33

P: n/a
Ian Collins <ia******@hotmail.comwrote:
James Dow Allen wrote:

I also object to the idea that complex expressions should
be avoided. I frequently write complicated variants of
if (0
|| foo1 && foo2 && foo3
|| foo4 && foo5 && foo6
|| foo7 && foo8 && foo9)
launch();
Often this is the simplest most readable form of the logic.
(The leading "0 ||" may seem silly, but gives the expression
an easily-read, easily-edited pattern.)
I'd prefer something like:

if( whateverTheConditionIsForLaunch() )
{
launch();
}
And what would you put in the horribly sTuDlYcApPeD and far too
verbosely named whateverTheConditionIsForLaunch()? Possibly something
like this:

int whateverTheConditionIsForLaunch(void)
{
return 0
|| foo1 && foo2 && foo3
|| foo4 && foo5 && foo6
|| foo7 && foo8 && foo9;
}

Not an improvement, IMO.

Richard

Dec 8 '06 #34

P: n/a
"santosh" <sa*********@gmail.comwrote:
christian.bau wrote:
could you please please please tell us why people from India write "I
have a doubt" instead of "I have a question"?

Because, in English as it's taught here the word doubt is synonymous
with the word question.
Then, beg pardon, what's taught there isn't English.

Richard
Dec 8 '06 #35

P: n/a
Richard Bos wrote:
Ian Collins <ia******@hotmail.comwrote:

>>James Dow Allen wrote:
>>>I also object to the idea that complex expressions should
be avoided. I frequently write complicated variants of
if (0
|| foo1 && foo2 && foo3
|| foo4 && foo5 && foo6
|| foo7 && foo8 && foo9)
launch();
Often this is the simplest most readable form of the logic.
(The leading "0 ||" may seem silly, but gives the expression
an easily-read, easily-edited pattern.)

I'd prefer something like:

if( whateverTheConditionIsForLaunch() )
{
launch();
}


And what would you put in the horribly sTuDlYcApPeD and far too
verbosely named whateverTheConditionIsForLaunch()? Possibly something
The name would be something that explained the condition.
like this:

int whateverTheConditionIsForLaunch(void)
{
return 0
|| foo1 && foo2 && foo3
|| foo4 && foo5 && foo6
|| foo7 && foo8 && foo9;
}

Not an improvement, IMO.
Maybe not in this case, but if the condition was complex enough to
justify a comment, then it would.

--
Ian Collins.
Dec 8 '06 #36

P: n/a
Richard Bos wrote:
"santosh" <sa*********@gmail.comwrote:
christian.bau wrote:
could you please please please tell us why people from India write "I
have a doubt" instead of "I have a question"?
Because, in English as it's taught here the word doubt is synonymous
with the word question.

Then, beg pardon, what's taught there isn't English.
I didn't realise that English had been standardised by the ISO.

Dec 8 '06 #37

P: n/a
Richard Bos <rl*@hoekstra-uitgeverij.nlwrote:
Then, beg pardon, what's taught there isn't English.
The last Queen's English more so than this one's, apparently.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Dec 8 '06 #38

P: n/a
santosh wrote:
Richard Bos wrote:
>>"santosh" <sa*********@gmail.comwrote:

>>>christian.bau wrote:

could you please please please tell us why people from India write "I
have a doubt" instead of "I have a question"?

Because, in English as it's taught here the word doubt is synonymous
with the word question.

Then, beg pardon, what's taught there isn't English.

I didn't realise that English had been standardised by the ISO.
Can you point us to a dictionary that lists doubt as a synonym of question?

--
Ian Collins.
Dec 8 '06 #39

P: n/a

Ian Collins wrote:
santosh wrote:
Richard Bos wrote:
>"santosh" <sa*********@gmail.comwrote:
christian.bau wrote:

could you please please please tell us why people from India write "I
have a doubt" instead of "I have a question"?

Because, in English as it's taught here the word doubt is synonymous
with the word question.

Then, beg pardon, what's taught there isn't English.
I didn't realise that English had been standardised by the ISO.
Can you point us to a dictionary that lists doubt as a synonym of question?
And can you point us to a country that enforces the English vocabulary
of it's people with a dictionary?

Dec 8 '06 #40

P: n/a
santosh wrote:
Ian Collins wrote:
>>santosh wrote:
>>>Richard Bos wrote:

"santosh" <sa*********@gmail.comwrote:

>christian.bau wrote:
>
>>could you please please please tell us why people from India write "I
>>have a doubt" instead of "I have a question"?
>
>Because, in English as it's taught here the word doubt is synonymous
>with the word question.

Then, beg pardon, what's taught there isn't English.

I didn't realise that English had been standardised by the ISO.

Can you point us to a dictionary that lists doubt as a synonym of question?

And can you point us to a country that enforces the English vocabulary
of it's people with a dictionary?
I'm just curious where the usage originated, no offense intended.

--
Ian Collins.
Dec 8 '06 #41

P: n/a
Ian Collins wrote:
santosh wrote:
Ian Collins wrote:
>santosh wrote:

Richard Bos wrote:

"santosh" <sa*********@gmail.comwrote:

christian.bau wrote:

>could you please please please tell us why people from India write "I
>have a doubt" instead of "I have a question"?

Because, in English as it's taught here the word doubt is synonymous
with the word question.

Then, beg pardon, what's taught there isn't English.

I didn't realise that English had been standardised by the ISO.
Can you point us to a dictionary that lists doubt as a synonym of question?
I'm not sure if purists will find it acceptable, but here's a link. The
word question is listed as a synonym for doubt, when the latter is used
as a verb.

<http://thesaurus.reference.com/search?q=doubt>
And can you point us to a country that enforces the English vocabulary
of it's people with a dictionary?
I'm just curious where the usage originated, no offense intended.
Well, I'm merely guessing but I think doubt is used to signify
uncertainity regarding the answer to the problem. So essentially,
instead of saying that they have a question, they're saying that
they're _uncertain_ of the answer to their problem, i.e. doubtful about
the answer. It's rather awkward and possibly not correct, but it does
seem to be idiomatic here.

As for where, I've no idea. Public schools perhaps. Really good English
teachers are rather rare. Most do a reasonable job. Further though it's
learnt academically, it's not, obviously, used regularly.

Dec 8 '06 #42

P: n/a
James Dow Allen wrote:
CBFalconer wrote:
>Christopher Benson-Manica wrote:
>>Am I the only poster who abhors explicit parentheses in such simple
cases?

No.
>Because the C rules are weird and wonderful, and totally confusing
to anyone used to a rational set of rules.

Many of the unusual precedences are easy to remember
when you notice a pattern: "&" is spelled similarly to "&&",
so like the latter "&" has a low precedence. Similarly ">"
and "<" have low precedence and so do ">>" and "<<".
(Obviously the pattern doesn't follow a simple rule --
& is higher than && but << is higher than < -- but that
isn't a source of confusion.)

I also object to the idea that complex expressions should
be avoided. I frequently write complicated variants of
if (0
|| foo1 && foo2 && foo3
|| foo4 && foo5 && foo6
|| foo7 && foo8 && foo9)
launch();
Often this is the simplest most readable form of the logic.
(The leading "0 ||" may seem silly, but gives the expression
an easily-read, easily-edited pattern.)
I would write that as:

if ((foo1 && foo2 && foo3) ||
(foo4 && foo5 && foo6) ||
(foo7 && foo8 && foo9))
launch();

leaving very little doubt, and consuming less vertical space.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Dec 8 '06 #43

P: n/a
Ian Collins wrote:
santosh wrote:
>Richard Bos wrote:
>>>"santosh" <sa*********@gmail.comwrote:
christian.bau wrote:

could you please please please tell us why people from India
write "I have a doubt" instead of "I have a question"?

Because, in English as it's taught here the word doubt is
synonymous with the word question.

Then, beg pardon, what's taught there isn't English.

I didn't realise that English had been standardised by the ISO.

Can you point us to a dictionary that lists doubt as a synonym of
question?
I doubt that such a dictionary exists. <grin>

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Dec 8 '06 #44

P: n/a
CBFalconer <cb********@yahoo.comwrote:
Christopher Benson-Manica wrote:
ma**********@pobox.com wrote:

(WRT "A && B || C"):
Before putting the file back in to your repository, why not add
the parentheses so that the next time you or someone else reads
the file, they can see what that line of code means straight away?
Am I the only poster who abhors explicit parentheses in such simple
cases? If we are to assume that the code maintainer cannot be
trusted to know or figure out the correct order of evaluation, what
argues against such abominations as
No. I find overindulgence in parens illegible, as well.
Because the C rules are weird and wonderful, and totally confusing
to anyone used to a rational set of rules.
Totally? Methinks thou exaggeratest.
If you need to rely on
"precedence" beyond multiplicative, additive, logical (highest to
lowest) use explicit parentheses to ensure readability.
And this case involved... logical operators.

Besides, there are really only three cases which are confusing, and one
of them is not that common:

- the bitwise operators;
- the shift operators;
- the relative precedence of the ternary, assignment, and comma
operators (among these three; not with respect to the others).
Even algebraic precedence is apparently unknown to the
manufacturers of most 4 function calculators.
I think you'll find that this is intentional, and has nothing to do with
maths and everything with accounting.

Richard
Dec 8 '06 #45

P: n/a
"santosh" <sa*********@gmail.comwrote:
CBFalconer wrote:
santosh wrote:
christian.bau wrote:
<snip>
>and could you please please please tell us why people from India
>write "I have a doubt" instead of "I have a question"?
>
Because, in English as it's taught here the word doubt is synonymous
with the word question.
The usage seems odd to us, but the meaning is clear. More to the
point, why do many Indians persist in using silly abbreviations
such as u, ur, etc. Did they pick it up from the kewl script
kiddies or other low lifes.

It's the result of the rampant use of cell phones with SMS facility.
That's no excuse. SMS is ridiculously popular here, as well, and
SMS-sp3k is used here, too, including in IM and email from school
children, but you rarely see anyone use it after they grow up, and
certainly not in a serious context.
Since each character costs a certain amount,
What a weird arrangement. Over here, each SMS costs something, but that
amount is nothing to do with the length of the message, and everything
with whom you are sending it to.
ridiculous abbreviations become the norm, gradually invading into email,
forums and probably even snail mail, God forbid if I know.
God forbid _that_ you know. (But I suspect most native speakers would
get that wrong, as well.)
Cost is also, partly, the reason why the very vast majority use Google
Groups to access Usenet. Subscriptions with news providers are not
cheap, (especially if you consider that almost no Indian ISP provides
Usenet access as a part of their package), and hunting around for
public/free news servers is too much of a technical hassle.
news.individual.net. Spread the word.

Richard
Dec 8 '06 #46

P: n/a

CBFalconer wrote:
Ian Collins wrote:
>>"santosh" <sa*********@gmail.comwrote:
christian.bau wrote:

could you please please please tell us why people from India
write "I have a doubt" instead of "I have a question"?

Because, in English as it's taught here the word doubt is
synonymous with the word question.
Can you point us to a dictionary that lists doubt as a synonym of
question?

I doubt that such a dictionary exists. <grin>
I question your sanity.

The verb 'question' and the verb 'doubt' can in some contexts be
synonymous. Unfortunately the nouns never are.

Dec 8 '06 #47

P: n/a
"santosh" <sa*********@gmail.comwrote:
Ian Collins wrote:
santosh wrote:
Richard Bos wrote:
>
>>"santosh" <sa*********@gmail.comwrote:
>>
>>>christian.bau wrote:
>>>
>>>>could you please please please tell us why people from India write "I
>>>>have a doubt" instead of "I have a question"?
>>>
>>>Because, in English as it's taught here the word doubt is synonymous
>>>with the word question.
>>
>>Then, beg pardon, what's taught there isn't English.
>
I didn't realise that English had been standardised by the ISO.
>
Can you point us to a dictionary that lists doubt as a synonym of question?

And can you point us to a country that enforces the English vocabulary
of it's people with a dictionary?
No.

Basically, by using "doubt" as if it meant "question", you're not
breaking any constraints, but you _are_ invoking undefined linguistic
behaviour. Don't complain about any resulting conversational bus error.

Richard
Dec 8 '06 #48

P: n/a
Richard Bos wrote:
>
"santosh" <sa*********@gmail.comwrote:
Because, in English as it's taught here the word doubt is synonymous
with the word question.

Then, beg pardon, what's taught there isn't English.
I think Indian English qualifies as a dialect of English.

In the USA, you can get in trouble with the law
if they find a silencer in your car.

In England, you can get in trouble for running your car without one.

--
pete
Dec 8 '06 #49

P: n/a
In article <45****************@news.xs4all.nl>,
Richard Bos <rl*@hoekstra-uitgeverij.nlwrote:
>Because, in English as it's taught here the word doubt is synonymous
with the word question.
>Then, beg pardon, what's taught there isn't English.
It's not British English, and I doubt that it's American English,
but it may well be Indian English. All part of the Imperial legacy..

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Dec 8 '06 #50

122 Replies

This discussion thread is closed

Replies have been disabled for this discussion.