pa********@hotm ail.com said:
I am not trying anything.
just trying to understand the scope of typecasting on the left side.
A cast doesn't of itself yield a modifiable lvalue, so the result of a cast
expression cannot of itself receive an assignment.
Since I saw some code similar to that.
Then it wasn't, strictly speaking, C code.
I was confused initially.
But do you see any potential for the above construct.
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?
@(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 think you need to consider more carefully the responses that you've
received so far. They're telling you something important, but you don't
seem to be getting it. Where a is a float, the expression (int)a = getc()
is simply meaningless. It's not legal C. Not even if we replace getc with
getchar.
Let's see what the compiler makes of it:
me@here:~/scratchcat foo.c
#include <stdio.h>
int main(void)
{
float FloatingPointOb ject;
(int)FloatingPo intObject = getchar();
printf("%f\n", FloatingPointOb ject);
return 0;
}
me@here:~/scratchmake
gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-ffloat-store -O2 -g -pg -c -o foo.o foo.c
foo.c: In function `main':
foo.c:6: warning: ANSI C forbids use of cast expressions as lvalues
foo.c:6: warning: value computed is not used
You see? You're just not supposed to do that.
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999