P
parag_paul
Can this be done
float a;
(int) a = getc();
float a;
(int) a = getc();
Can this be done
float a;
(int) a = getc();
[email protected] said:Can this be done
float a;
(int) a = getc();
Can this be done
float a;
(int) a = getc();
Kenneth Brody said:No. (Check your manual and/or this group's archives for a description
of "l-value".)
Can this be done
float a;
(int) a = getc();
I am not trying anything.
just trying to understand the scope of typecasting on the left side.
Since I saw some code similar to that.
I was confused initially.
But do you see any potential for the above construct.
@(all who are talking about lvalue)
I am a bit familiar with the concept myself. Just trying to get an
insight from the others on the casting on the left.
I am not trying anything.
just trying to understand the scope of typecasting on the left side.
Since I saw some code similar to that.
I was confused initially.
But do you see any potential for the above construct.
@(all who are talking about lvalue)
I am a bit familiar with the concept myself. Just trying to get an
insight from the others on the casting on the left.
Eric Sosman said:Remember this: The cast operator is an *operator*. Like
other operators, it takes operands (one, for a cast) and yields
a value. A *value*, not an assignable object.
[...]Richard Heathfield said:(e-mail address removed) said:
A cast doesn't of itself yield a modifiable lvalue, so the result of a cast
expression cannot of itself receive an assignment.
Then it wasn't, strictly speaking, C code.
Er, no, none at all. Do you? What do you think such a construct would mean?
C doesn't offer a meaning for it, so what meaning do you think it should
have?
I am not trying anything.
just trying to understand the scope of typecasting on the left side.
Since I saw some code similar to that.
I was confused initially.
But do you see any potential for the above construct.
@(all who are talking about lvalue)
I am a bit familiar with the concept myself. Just trying to get an
insight from the others on the casting on the left.
¬a\\/b said:In data Thu, 11 Oct 2007 05:30:33 -0700, parag_paul scrisse:
the cast on the left has a sense only where there is something like
*( obj *)
int b=0;
*(char*)&b=33;
it is not portable etc but sometime is useful
or in the case of compare function for qsort
than it can be useful for write things like
int i;
if( (unsigned)i> INT_MAX) ...
in the case INT_MAX is "traslated" to unsigned integer
Several operators yield assignable values, * for example, so remembering
that a cast is an operator doesn't necessarily help.
I usually ignore you, but here you've made a simple error. Neither of
your examples is relevant to the discussion, since neither one
attempts to use a cast as an lvalue.
In the first case, ``*(char*)&b=33;'', the cast appears as part of the
expression on the LHS of the assignment, but the full LHS is a
dereference, not a cast. In the second, ``(unsigned)i> INT_MAX'', the
cast is the LHS of the ">" operator, not of an assignment.
¬a\\/b said:In data Sat, 13 Oct 2007 14:27:13 -0700, Keith Thompson scrisse:
so where is the differece in your gcc exenstion from
int a=0;
*(char*)&a=43;
and the code
int a=0;
(char)a=43;
This would be a fun interview question to help sort out the women from
the girls:
"What's wrong with the following code:
int a=0;
int *p=NULL;
p++=&a;
a) Nothing
b) Constraint violation: p++ is not a modifiable lvalue
c) Undefined behavior: arithmetic on a null pointer
d) Undefined behavior: p is modified twice with no intervening
sequence point
e) Some combination of the above"
Kenneth Brody said:Then, of course, there is the deprecated(?) "=&" operator.
The =op forms of assignment were listed as anachronisms even in K&R1,
and they aren't in C89 or C99 at all.
Harald van Dijk said:Right, and as a result, x=&a is valid C89 and C99, takes the address of
a, and assigns that pointer value to x. If =& were still a single
operator, it would be equally valid, but with a completely different
meaning.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.