473,215 Members | 1,264 Online

# I have a doubt

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
122 4106
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
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

"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
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
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
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
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

"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
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

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
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
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
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
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
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.

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
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

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
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
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
have a doubt" instead of "I have a question"?

Dec 7 '06 #20
>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
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
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
have a doubt" instead of "I have a question"?
(Apologies for the line length.)

--
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
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
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
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
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
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.
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++)));

--
Ben.
Dec 8 '06 #26
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
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.
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
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.

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++)));

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
>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))

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:

In those days, no casts were required, and none used. :-)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
Reading email is like searching for food in the garbage, thanks to spammers.
Dec 8 '06 #30

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

James Dow Allen

Dec 8 '06 #31
CBFalconer wrote:
santosh wrote:
christian.bau wrote:
<snip>
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
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
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
I'd prefer something like:

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

--
Ian Collins.
Dec 8 '06 #33
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
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
"santosh" <sa*********@gmail.comwrote:
christian.bau wrote:
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
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

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
Richard Bos wrote:
"santosh" <sa*********@gmail.comwrote:
christian.bau wrote:
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
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
santosh wrote:
Richard Bos wrote:
>>"santosh" <sa*********@gmail.comwrote:

>>>christian.bau wrote:

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

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

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
santosh wrote:
Ian Collins wrote:
>>santosh wrote:
>>>Richard Bos wrote:

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

>christian.bau wrote:
>
>>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
Ian Collins wrote:
santosh wrote:
Ian Collins wrote:
>santosh wrote:

Richard Bos wrote:

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

christian.bau wrote:

>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
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
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
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
Ian Collins wrote:
santosh wrote:
>Richard Bos wrote:
>>>"santosh" <sa*********@gmail.comwrote:
christian.bau wrote:

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
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
"santosh" <sa*********@gmail.comwrote:
CBFalconer wrote:
santosh wrote:
christian.bau wrote:
<snip>
>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.
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.

Richard
Dec 8 '06 #46

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

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>

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

Dec 8 '06 #47
"santosh" <sa*********@gmail.comwrote:
Ian Collins wrote:
santosh wrote:
Richard Bos wrote:
>
>>"santosh" <sa*********@gmail.comwrote:
>>
>>>christian.bau wrote:
>>>
>>>>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
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
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

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