On Apr 7, 2005 6:24 AM, Valnir <[EMAIL PROTECTED]> wrote:
> Would it work just as well to do like the following?
>
> if ( !str_cmp(word,"Clan") )
> {
> char name[MIL] = fread_string(fp);
> ch->clan = clan_lookup(name);
> fMatch = TRUE;
> break;
> }
>
That will not work. fread_string returns the pointer to a allocated
chunk of characters. If you'll notice, it returns
str_dup(whatisread);, so its allocated there. If you really want to
avoid such things, write a function similar to fread_string but
doesn't allocate memory.
As for my prior rant, const is not needed. I mean, of course, you can
use it. I use static myself. It sets a defined place in the heap for
the variable, meaning it will never need to free/allocate the
variable. Send_to_char and functions like it are called frequently
throughout the life of the program, and if it is not static, then
memory will keep being allocated and freed from the stack. It isn't a
huge deal, I just did it to optimize my send_to_char. Its a
nit-picking thing :P