This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Who is responsible for ensuring a char is in range?


On Mon, May 03, 1999 at 10:49:41AM +0200, Andreas Schwab wrote:
> Erik Corry <erik@arbat.com> writes:
> 
> |> I.e. the called function is masking the char with 0xff and
> |> so is the calling function.  This seems like needless double
> |> work, but I can't work out from the C standard (or is this a
> |> calling convention thing) who should really be doing this.
> 
> The standard does not care.  It only says that a value of a type that is
> narrower than int is promoted to (unsigned) int, but the compiler can
> leave out the promotion if it knows that the behaviour does not change.
> 
> |> Is it necessary to do it both places?
> 
> Only for compatibility with K&R C, where passing a char actually means
> passing an int.

So if we are compiling with -ansi we could assume the
promotion (ie the masking) has already taken place at the
point where the function is called.  And at that point we
could obviously optimise it away if it makes no difference
(we already do this some of the time).

-- 
Erik Corry erik@arbat.com           Ceterum censeo, Microsoftem esse delendam!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]