home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!uunet.ca!geac!zooid!ross
- From: Ross Ridge <ross@zooid.guild.org>
- Subject: Re: HIgher problems at hand. HELP!
- Organization: ZOOiD BBS
- Date: Mon, 27 Jul 1992 21:23:11 GMT
- Message-ID: <1992Jul27.212311.28125@zooid.guild.org>
- References: <Brv6oD.Dq5@usenet.ucs.indiana.edu> <1992Jul25.142216.5636@druid.uucp> <9220806.7841@mulga.cs.mu.OZ.AU>
- Lines: 53
-
- fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
- >darcy@druid.uucp (D'Arcy J.M. Cain) writes:
- >>/*
- >> * strstr - find first occurrence of wanted in s
- >> *
- >> * based on code by Henry Spencer
- >> * modified for ANSI by D'Arcy J.M. Cain
- >> */
- >>
- >>/* The following define required for full checking. The problem is that */
- >>/* the function has to ultimately assign a const char * to the return */
- >>/* value which has to be char *. The answer is to drop the use of */
- >>/* const in this module and trust the code to do the right thing */
- >>#define const
- >
- >Yuck!
- >Do *not* #define keywords unless you have absolutely no alternative.
- >
- >>#include <string.h>
- >
- >Now what happens if string.h happens to contain
- > const CHAR_BIT = 8;
- >or some such?
-
- Include files are very unlikely to contain external definitions like this.
- Remeber in C there is world of difference between "#define CHAR_BIT 8"
- and "/*static*/ const /*int*/ CHAR_BIT = 8;". But who knows what's
- in <string.h> so it would be better if the "#define const" was placed
- after the "#include <string.h>".
-
- >>char *strstr(const char *s, const char *wanted)
- >
- >This is a *different* prototype to the externally visible one, since
- >this one doesn't include "const".
-
- What externally visable one?
-
- >> return(s);
- >
- >The solution to the const problem is just to put a cast in the final return
- >statement:
- > return (const char *) s;
-
- You mean "return (char *) s;". This ia probably the better over all
- solution, but simply not using const will work to.
-
- Ross Ridge
-
- --
- Ross Ridge - The Great HTMU l/ //
- [OO][oo]
- ross@zooid.guild.org /()\/()/
- uunet.ca!zooid!ross db //
-