Re: buf[]

From: Jeremy Elson (jelson@blaze.cs.jhu.edu)
Date: 09/13/95


> > why is buf[] declared in so many places to be rather small in the  
> .c files
> > when it is declared in structs.h and db.h to be size
> > MAX_STRING_LENGTH?
> > this seems a little odd to me.

> Well, because the circle code is a mess

Well, that's certainly a subjective thing...

> and the compiler
> and linker don't care.
> 
> If you declare buf[32] it will replace (override)
> the global buf variable by a local of size 32Bytes until
> the function is left.

There is an excellent reason for declaring local buf's.  Consider the
following piece of code:

ACMD(my_command)
{
  sprintf(buf, "Hello");
  do_some_other_processing();
  strcat(buf, "\r\n");
  send_to_char(buf, ch);
}

What if do_my_own_processing uses buf[], too?  Chaos.

Functions that get called from other functions often have their own local
bufs to avoid such problems.

-Jeremy



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