Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2001:
[Freeciv-Dev] Re: [PATCH] base_real_map_distance (PR#1049)
Home

[Freeciv-Dev] Re: [PATCH] base_real_map_distance (PR#1049)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxx
Cc: Freeciv List <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: [PATCH] base_real_map_distance (PR#1049)
From: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>
Date: Wed, 05 Dec 2001 22:04:05 -0500

At 02:07 PM 01/12/05 -0500, Jason Short wrote:
>Raimar Falke wrote:
>
>> On Wed, Dec 05, 2001 at 04:59:13AM -0800, Raahul Kumar wrote:
>>>--- Petr Baudis <pasky@xxxxxxxxxxx> wrote:
>
>>>>Thing I have problem with is:
>>>>+     dx = abs(dx), dy = abs(dy);
>>>>I think it should be rather
>>>>+     dx = abs(dx); dy = abs(dy);
>>>>What do you think?
>
>> From the language syntax point of view both version are the same. I
>> know that Ross sometimes prefer the , version. It looks like also
>> Jason prefer it (Jason: under which conditions?). So I would like to
>> add this to the style guide questionnaire:
>> 
>> 
>>  <some number>
>>  This isn't about initialization!
>> 
>> /* A */
>>   x = punit->x, y = punit->y;
>> 
>> /* B */
>>   x = punit->x;
>>   y = punit->y;
>> 
>> Something like
>>   x = punit->x; y = punit->y;
>> will not work because it will be broken up by indent.
>
>I do not really have a preference.  But I don't find the comma notation 
>unreadable at all, and I guess Ross's ways have rubbed off a little.  It 
>never really occurred to me that this might be a problem for other people.
>
>jason

One use of the comma operator is for grouping sets of operations into
a single statement. This is both a documentation alert to the programmer
and a safety measure for compiles.

The bug this guarantees never bites you, in addition to someone separating
the set or deleting part of it, is

  if( cond() )
    x = punit->x, y = punit->y;

  if( cond() )
    x = punit->x; y = punit->y;

Note comma operators are often used in macros in similar ways, or 
anything you want to treat as a single expression.

You can always tell "real" C programmers by their understanding level of
some of these more subtle uses of the language.

Cheers,
RossW
=====




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