httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <dgau...@arctic.org>
Subject Re: overloaded functions
Date Mon, 28 Jun 1999 16:20:29 GMT


On Fri, 25 Jun 1999, Ben Laurie wrote:

> Dean Gaudet wrote:
> > 
> > Oh, one thing ages back which I said was nifty in C++:
> > 
> >     char *strchr(char *, int);
> >     const char *strchr(const char *, int);
> > 
> > That way you don't have to lose the "const" when you use this on a const
> > string... this helps detect bugs at compile time.
> > 
> > But gnu c gives me what I want:
> > 
> > #ifef __GNUC__
> > #define my_strchr(a,b)  ((typeof (a)) strchr((a), (b)))
> > #else
> > #define my_strchr strchr
> > #endif
> > 
> > ... which is good enough for most of the developers to get the warnings :)
> 
> OK. Another one I keep bumping into is this:
> 
> 	unsigned char *x,*y;
> 
> 	y=strchr(x,' ');
> 
> compiler meeps because x,y should be char *. Yes, we can do ustrchr, but
> it gets messy (namewise) when you have three or more char * arguments.
> 
> Any clever ideas for that?

Nope... the typeof thing would work just fine if C required a warning for: 

char *y;
unsigned char *x = y;

... I suppose someone could add such a warning to gcc ;)  I wonder what
it'd catch.  ISTR such a switch existing, but can't find it right now.

("char" is a magic type in C, the implementation can decide if it's signed
or unsigned...) 

Dean


Mime
View raw message