Re: double casts
From: Dan Pop (Dan.Pop_at_cern.ch)
Date: 11/05/03
- Next message: Glen Herrmannsfeldt: "Re: Use of nested loops."
- Previous message: Glen Herrmannsfeldt: "Re: va_arg and short"
- In reply to: Joona I Palaste: "Re: double casts"
- Next in thread: Joona I Palaste: "Re: double casts"
- Reply: Joona I Palaste: "Re: double casts"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 5 Nov 2003 16:56:42 GMT
In <bob3ic$nb4$2@oravannahka.helsinki.fi> Joona I Palaste <palaste@cc.helsinki.fi> writes:
>Dan Pop <Dan.Pop@cern.ch> scribbled the following:
>> In <boalcr$eg7$1@oravannahka.helsinki.fi> Joona I Palaste <palaste@cc.helsinki.fi> writes:
>>>And even if that's true, there's no guarantee the host CPU returns
>>>scalars and pointers in the same way. It could use different registers,
>>>for instance, in which case p2 will be pure garbage.
>
>> Huh? I can see no function call in the code. What am I missing?
>
>You're missing the fact that I can sometimes fumble up in my
>terminology. By "return" I meant something like "store". Is a cast to
>an (int *) allowed to read from a different register than a cast to a
>(long)?
Now, you're severely confused: the evaluation of an expression is defined
in terms of values, it is immaterial where these values are stored, as
long as all of them are obtained via legit means. It is compiler's job
to do the right thing and it has all the necessary information for that.
Such things can happen only when misdeclared functions are involved.
Consider the following *complete* program (on a C89 implementation):
int main()
{
return sin(0.0);
}
In the absence of an explicit declaration, sin() is implicitly declared
as returning int. Therefore, after generating the function call, the
compiler will expect the return value to be in whatever place a function
returning int will put its return value. But the sin() function doesn't
"know" that and it will put its return value in whatever place a function
returning double is supposed to put its return value. The final result
being that return will use an indeterminate value (but undefined behaviour
has already been invoked by the time sin() was called.
Even worse things can happen if the stack is used for passing back the
return value, because the caller generates a certain stack layout, while
the callee expects another, possibly corrupting stack data containing the
callers local variables or its return address.
Dan
-- Dan Pop DESY Zeuthen, RZ group Email: Dan.Pop@ifh.de
- Next message: Glen Herrmannsfeldt: "Re: Use of nested loops."
- Previous message: Glen Herrmannsfeldt: "Re: va_arg and short"
- In reply to: Joona I Palaste: "Re: double casts"
- Next in thread: Joona I Palaste: "Re: double casts"
- Reply: Joona I Palaste: "Re: double casts"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|