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


if (SELF_BLOCK | is_locked) param = NO_LOCK;
else param = 0;
__db_mutex_setup( ..., &m, param);


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

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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]