Re: handler

From: Chris Gilbert (chris@buzzbee.freeserve.co.uk)
Date: 01/19/00


Mac Manson wrote:
>
> When recently adding the abbreviations snippet I encountered a problem with
>
> gcc -c -g -O2 -Wall  handler.c
> handler.c:62: conflicting types for `isname'
> handler.h:25: previous declaration of `isname'
>
> so I looked into the h file and seen that it was making the isname a const
> char
> and the snippet used a plain char. I kind of fixed it by adding a const onto
> the chars
> in the snippet, but I get the following
>
> gcc -c -g -O2 -Wall  handler.c
> handler.c: In function `isname':
> handler.c:68: warning: passing arg 1 of `strtok' discards `const' from
> pointer target type
> handler.c:72: warning: passing arg 1 of `free' discards `const' from pointer
> target type
> handler.c:75: warning: passing arg 1 of `free' discards `const' from pointer
> target type
>
> When I compile and run, you can abbreviate words ok, and I haven't noticed
> anything bad going on.
> So is this a bad warning or not? Here is the complete code I've added

YES!  if you declare something as const the compiler/linker has the
right to assume that it's never written to so it may make assumptions
about it.  strtok is definetly destructive, try man strtok and note:

BUGS
       Never use this function.  This function modifies its first
       argument.   The  identity  of  the delimiting character is
       lost.  This function cannot be used on constant strings.

so newlist and curtok should be just char *'s, this is why it duplicates
the input strings.  Although I'm never quite sure what isname is meant
to achieve I've got 3 different versions floating around, I should
really sit down and see where they're used and why.

Chris


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/10/01 PDT