Why was there no compiler error?

  • Thread starter Man-wai Chang to The Door (24000bps)
  • Start date
M

Man-wai Chang to The Door (24000bps)

http://www.kernel.org/diff/diffview.cgi?file=/pub/linux/kernel/v2.6/incr/patch-2.6.32.3-4.bz2;z=112

--
@~@ Might, Courage, Vision, SINCERITY.
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (x86_64 Ubuntu 9.10) Linux 2.6.32.3
^ ^ 17:13:02 up 4 days 6:24 1 user load average: 3.33 2.68 1.79
ä¸Â借貸! ä¸Âè©Â騙! ä¸Âæ´交! ä¸Â打交! ä¸Â打劫!
ä¸Â自殺! 請考慮綜æ´ (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa
 
B

Bart van Ingen Schenau


The link shows a code change from code along the lines of:
a = 42, foo(a);
to
a = 42;
foo(a);

The question, as placed in the subject is: Why did the compiler not
complain about the old code?

The answer is that the old code uses the comma-operator to separate
two expressions.
The rewrite is semantically identical to the original code. The
rewrite is preferable, because it is mode ideomatic code and leads to
fewer questions. :)

Bart v Ingen Schenau
 
M

Man-wai Chang to The Door (24000bps)

The link shows a code change from code along the lines of:
a = 42, foo(a);
to
a = 42;
foo(a);
The rewrite is semantically identical to the original code. The
rewrite is preferable, because it is mode ideomatic code and leads to
fewer questions. :)

Thanks

--
@~@ Might, Courage, Vision, SINCERITY.
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (x86_64 Ubuntu 9.10) Linux 2.6.32.3
^ ^ 19:59:02 up 4 days 9:10 1 user load average: 3.62 3.52 3.39
ä¸å€Ÿè²¸! ä¸è©é¨™! ä¸æ´äº¤! ä¸æ‰“交! ä¸æ‰“劫! ä¸è‡ªæ®º! è«‹è€ƒæ…®ç¶œæ´ (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa
 
T

Timothy Madden

Man-wai Chang to The Door (24000bps) said:

Because the comma (",") is also an operator in C++, which can be used in
expressions, not only a punctuator. So the following is a valid C++
expresion:

_expr_, _expr_, _expr_, ...

sama as (a + b) or (expr + expr + expr + ...) is a valid expression,
and, as any expression, it can be used in an expression-statement

_expr_, _expr_ ;
a + b ;

by adding the semicolon ";".

So the old code

request->alpha2[0] = alpha2[0];
request->alpha2[1] = alpha2[1];
request->initiator = NL80211_REGDOM_SET_BY_USER,

queue_regulatory_request(request);

was seen as

request->alpha2[0] = alpha2[0];
request->alpha2[1] = alpha2[1];

( request->initiator = NL80211_REGDOM_SET_BY_USER ) ,
( queue_regulatory_request(request) );

which is valid C++, with the last two lines being an
expression-statement, and which fortunately does the same thing as the
new patched version.

Timothy Madden
 
M

Man-wai Chang to The Door (24000bps)

which is valid C++, with the last two lines being an
expression-statement, and which fortunately does the same thing as the
new patched version.

1. smells like ambiguity though harmless, doesn't it?
2. really no side-effect in terms of compilation?
3. did that kernel programmer want to make a point? ;)

--
@~@ Might, Courage, Vision, SINCERITY.
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (x86_64 Ubuntu 9.10) Linux 2.6.32.4
^ ^ 21:55:01 up 4:58 0 users load average: 1.00 1.02 1.00
ä¸å€Ÿè²¸! ä¸è©é¨™! ä¸æ´äº¤! ä¸æ‰“交! ä¸æ‰“劫! ä¸è‡ªæ®º! è«‹è€ƒæ…®ç¶œæ´ (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa
 
T

Timothy Madden

Man-wai Chang to The Door (24000bps) said:
1. smells like ambiguity though harmless, doesn't it?
2. really no side-effect in terms of compilation?
3. did that kernel programmer want to make a point? ;)

No side-effects.

When you know about it since a long time, the ambiguity is only in the
potential for someone else reading your code to be confused, which is
why the patched (corected) version should be used.


Looking at the blank line between the sub-expressions of the
comma-expression in the last statement in the old code, one could say
there was no point to be made by the kernel programmer, just a typo...
 
M

Man-wai Chang to The Door (24000bps)

int a = 42, foo(a);
then foo(a) is not called any more. Instead, a new variable foo is created
and initialized by the value of a. One might not notice this change because
the code still compiles, but of course it does not work properly any more
when used by the most important customer. So I would say the code is a bit
fragile.

Now that's horrible... :)

--
@~@ Might, Courage, Vision, SINCERITY.
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (x86_64 Ubuntu 9.10) Linux 2.6.32.4
^ ^ 16:51:02 up 23:54 0 users load average: 1.00 1.00 1.00
ä¸å€Ÿè²¸! ä¸è©é¨™! ä¸æ´äº¤! ä¸æ‰“交! ä¸æ‰“劫! ä¸è‡ªæ®º! è«‹è€ƒæ…®ç¶œæ´ (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa
 

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
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top