[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bahamut ircd



M Campbell <mike@avendesora.net> writes:

> > > My 2?: It's the very rare source code that compiles without that
> > > "cast from integer to pointer of different size" warning.  I quit
> > > worrying about it many years ago.
> > 
> > It can be harmless in some cases, but it is certainly not a warning
> > that should be ignored, and it is usually easy to fix.
>
> Well, it definitely caused a problem in this case? And there are a
> lot more of these in this code I don't know anything about C, but I
> wouldn't mind trying to clean up the specific warnings that I get on
> compile.  Is this pretty basic stuff, or should I try to bug someone
> who knows C to do it?

Well, casting an integer to a pointer only makes sense when the
integer was cast to from a pointer previously. And then this operation
will only work if the integer type is at least as wide as a pointer.
Therefore, the integer should be of type size_t.

OTOH, sometimes people use void* to store "random stuff", e. g. either
an actual pointer or an integer value. This will yield the same
warning, but it's harmless in that case. To get rid of it, one should
use a union or an additional cast to size_t.

-- 
	Falk



Reply to: