Re: [BLACKBOX] Seasons Greetings from Linuxland

From: [at]} <Chris>
Date: Wed, 29 Dec 2010 09:35:22 +1030

----boundary-LibPST-iamunique-896880779_-_-
Content-type: text/plain

>-----Original Message-----
>From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
>Sent: Wednesday, 29 December 2010 2:01 AM
>To: BLACKBOX{([at]})nowhere.xy
>Subject: [BLACKBOX] Seasons Greetings from Linuxland
>
>A C programmer can make exactly the same argument that he/she
>has to evaluate an expression and then read two additional
>lines to understand what the outcome was if the initial
>complex expressions are expanded (a.k.a. made long winded).
>
>
> // z = x++ + ++y;
> ++y;
> z = x + y;
> x++;
>
>But which forms best express what the program writer intended?
>

The original point made by Wirth was related to the problem of parsing:

  x+++++y

It was your interpretation that it must have been intended to be:

  z = x++ + ++y;

However, if additional blanks are to be admitted, the C compiler I tested it
with (GCC 4.4.2) is also happy to compile:

        z = x+ + + ++y;
        z = x+ + + + +y;
        z = x++ + + +y;
        z = x+++ ++y;

so who can say what the program writer intended?

--------------------------------

However, my initial complaint about the ++ operator was not related to the
brevity of expressions. I was reporting a real life example of the
unintended consequences of the order of evaluation of expressions and the
involvement of side effects. I said that a few days ago a C programmer was
complaining in another group that the following "does not work, gives
unexpected results":

  digdata[digNr] = (bitdata[bitNr++] * 8) + (bitdata[bitNr++] * 4) +
(bitdata[bitNr++] * 2) + (bitdata[bitNr++]);

As it says in my ancient copy of K&R C (maybe C has been tightened up since
then but I don't think so?):

"In particular the compiler considers itself free to compute subexpressions
in the order it believes most efficient, even if the subexpressions involve
side effects. The order in which side effects take place is unspecified.
Expressions involving a commutative and associative operator (*, +, &, |, ^)
may be rearranged arbitrarily, even in the presence of parentheses; to force
a particular order of evaluation an explicit temporary must be used."

That is just one of many reasons why I believe that programming in C is akin
to running with chainsaws.

>Good program readability is important whatever the language
>which is being used and anything which enhances it is to be
>welcomed and anything which detracts from it is to be discouraged.
>

I agree with you 100%.

Regards,
Chris Burrows
CFB Software
http://www.cfbsoftware.com


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-896880779_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwID4tLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLVxw
YXINCj5Gcm9tOiBCbGFja0JveCBbbWFpbHRvOkJMQUNLQk9YQExJU1RTLk9CRVJPTi5DSF0gT24g
QmVoYWxmIE9mIExlcyBNYXlccGFyDQo+U2VudDogV2VkbmVzZGF5LCAyOSBEZWNlbWJlciAyMDEw
IDI6MDEgQU1ccGFyDQo+VG86IEJMQUNLQk9YQExJU1RTLk9CRVJPTi5DSFxwYXINCj5TdWJqZWN0
OiBbQkxBQ0tCT1hdIFNlYXNvbnMgR3JlZXRpbmdzIGZyb20gTGludXhsYW5kXHBhcg0KPlxwYXIN
Cj5BIEMgcHJvZ3JhbW1lciBjYW4gbWFrZSBleGFjdGx5IHRoZSBzYW1lIGFyZ3VtZW50IHRoYXQg
aGUvc2hlIFxwYXINCj5oYXMgdG8gZXZhbHVhdGUgYW4gZXhwcmVzc2lvbiBhbmQgdGhlbiByZWFk
IHR3byBhZGRpdGlvbmFsIFxwYXINCj5saW5lcyB0byB1bmRlcnN0YW5kIHdoYXQgdGhlIG91dGNv
bWU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dHdhcmVccGFyDQpodHRwOi8vd3d3LmNmYnNvZnR3YXJlLmNvbVxwYXINClxwYXINClxwYXINCi0t
LS1ccGFyDQpUbyB1bnN1YnNjcmliZSwgc2VuZCBhIG1lc3NhZ2Ugd2l0aCBib2R5ICJTSUdOT0ZG
IEJMQUNLQk9YIiB0byBMSVNUU0VSVkBMSVNUUy5PQkVST04uQ0hccGFyDQp9
----boundary-LibPST-iamunique-896880779_-_---
Received on Wed Dec 29 2010 - 00:05:22 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:20 UTC