From: George (greerga@CIRCLEMUD.ORG)
Date: 09/29/98

On Tue, 29 Sep 1998, Del Minturn wrote:

>I have never seen an if statement do this "if (x = y >= z)". I will bet
>if you change that, you will get some better results.
>If someone knows that this can be done or show me an application that
>does this, I would like to see it or understand what it is actually
>trying to compare. seems like your better off doing x = y && x >= z or
>x = y && y >= z

It's valid.  In fact, you'll find this gem in interpreter.c:

      if ((num = *temp - '1') < num_of_tokens && num >= 0) {

It could be re-written as:

      num = *temp - '1';
      if (num < num_of_tokens && num >= 0) {

with the same effect as the first one.  It's personal taste most of the
time.  Like:

  if ((new_buf->data = (char *)calloc(size + 1, sizeof(char))) == NULL)
  new_buf->data = (char *)calloc(size + 1, sizeof(char));
  if (new_buf == NULL)

Other applications:

  if (!*buf || !*buf2)
    send_to_char("Who do you wish to tell what??\r\n", ch);
  else if (!(vict = get_char_vis(ch, buf)))
    send_to_char(NOPERSON, ch);
  else if (is_tell_ok(ch, vict))
    perform_tell(ch, vict, buf2);

So you can do neater nesting.

George Greer, | Genius may have its limitations, but   (mostly) | stupidity is not thus handicapped.    |                  -- Elbert Hubbard

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

This archive was generated by hypermail 2b30 : 12/15/00 PST