[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] type cast prob.
From: |
Basile STARYNKEVITCH |
Subject: |
Re: [Tinycc-devel] type cast prob. |
Date: |
Wed, 6 Nov 2002 10:30:47 +0100 |
>>>>> "fabrice" == fabrice bellard <address@hidden> writes:
fabrice> Quoting s duclos <address@hidden>:
>> Hi,
>>
>> Got this code after expanding up a macro by hand.
>>
>> // t5.c main(){ float x; (int)x = (int)x; }
fabrice> I am not sure that doing (int)x = [...] is correct.
It is documented as a GCC extension. See the 'lvalues::' subsection in
the C extension section of the GCC info manual.
I am citing it here:
________________________________________________________________
Generalized Lvalues
===================
Compound expressions, conditional expressions and casts are allowed
as lvalues provided their operands are lvalues. This means that you
can take their addresses or store values into them.
[...]
A cast is a valid lvalue if its operand is an lvalue. A simple
assignment whose left-hand side is a cast works by converting the
right-hand side first to the specified type, then to the type of the
inner left-hand side expression. After this is stored, the value is
converted back to the specified type to become the value of the
assignment. Thus, if `a' has type `char *', the following two
expressions are equivalent:
(int)a = 5
(int)(a = (char *)(int)5)
________________________________________________________________
I leave up to Fabrice to implement it in tcc. I've got no idea if it
is easy to do or not.
And by the way I don't know what Sylvain expect his code to do. Does
he want to round up a to its floor? Or should this be a No-Op (since
assigning the same bits to a float).
Regards.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net
alias: basile<at>tunes<dot>org
8, rue de la Faïencerie, 92340 Bourg La Reine, France