[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gnumed-devel] (no subject)
From: |
Horst Herb |
Subject: |
Re: [Gnumed-devel] (no subject) |
Date: |
Mon, 22 Sep 2003 16:38:59 +1000 |
On Mon, 2003-09-22 at 20:42, syan tan wrote:
> From
>
> http://www.sleepycat.com/company/technical/sueweisspaper.pdf
>
> Scary language bug (order of precedence)
> if (we need a new mutex){
> __db_mutex_setup(..., &m,
> (SELF_BLOCK | is_locked ?
> NO_LOCK : 0));
> MUTEX_LOCK(m);
> }
This missing the obvious is facilitated by cryptic programming style.
If they had written it that way:
compare the three code blocks, and judge yourself:
> __db_mutex_setup(..., &m,
> (SELF_BLOCK | is_locked ?
> NO_LOCK : 0));
vs
if (SELF_BLOCK | is_locked) param = NO_LOCK;
else param = 0;
__db_mutex_setup( ..., &m, param);
vs
if is_locked param = NO_LOCK;
else param = 0;
_db_mutex_setup( ..., &m, (SELF_BLOCK|param));
Obvious, isn't it?
A good optimizing compiler would generate the same code for both code
versions anyway (provided "param" is not used again after that function
call)
I would say the lesson learned is that this programmer should get
his/her wrists smacked for unnecessarily cryptic programing styles. Hope
no gnumed programmer will commit that sin.
Horst