On Sat, 18 Jul 2009, Mukund Deshpande wrote:

> Hi uma,
> 
> #include <stdio.h>
> 
> int main(int argc, char *argv[]) {
> int *a;
> int **b;
> int *c;
> 
> c = (int *)a;
> b = &c;
> 
> return 0;
> }
> 
> This seems to work why?
> 
> thanks,
> 
> SMS
> 
> On Sat, Jul 18, 2009 at 2:01 PM, uma <u...@twincling.org> wrote:
> 
> >
> >
> > Hi Saifi,
> >
> > The following line should give compiler error
> > b = &(int *)a;
> >
> > '&' operator expects operand immediately, but not typecast operator or any
> > other expression.
> >
> > It could be corrected as:
> >
> >
> > #include <stdio.h>
> >
> > int main(int argc, char *argv[]) {
> > char *a;
> > int **b;
> > int *c;
> >
> > c = (int *)a;
> > b = &c;
> >
> > return 0;
> > }
> >
> > But the operation is not portable.
> >
> > thanks,
> > uma..
> >
> > On Sat, Jul 18, 2009 at 10:06 AM, Saifi Khan 
> > <saifi.k...@twincling.org<saifi.khan%40twincling.org>
> > >wrote:
> >
> > > Hi all:
> > >
> > > Here is a simple C code.
> > >
> > > #include <stdio.h>
> > >
> > > int main(int argc, char *argv[])
> > > {
> > > char *a;
> > >
> > > int **b;
> > >
> > > b = &(int *)a;
> > >
> > > return 0;
> > > }
> > >
> > >
> > > --
> > > any issues with this piece of code ?
> > >
> > >
> > > thanks
> > > Saifi.
> > >
> >

I. compiling with gcc

lval.c: In function 'main':
lval.c:9: error: lvalue required as unary '&' operand


II. compiling with clang/llvm

lval.c:9:9: error: address expression must be an lvalue or a function designator
    b = &(int *)a; 
        ^~~~~~~~~
1 diagnostic generated.


thanks
Saifi.

Reply via email to