Re: buf[]

From: DoDGeR (dodger@WPI.EDU)
Date: 09/13/95


thus on Wed, 13 Sep 95 18:49:32 EDT, Jeremy virtually scripted...

>> > 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
ok... that makes a lot of sense, any particular reason they all use the
same name? and not something like local_buf?



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