|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
simple C codeHi 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. |
|
|
Re: simple C codeHi 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.khan@...>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. > [Non-text portions of this message have been removed] |
|
|
Re: simple C codeHi 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 <uma@...> 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.khan@...<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. > > > > [Non-text portions of this message have been removed] > > > [Non-text portions of this message have been removed] |
|
|
Re: simple C codeOn 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 <uma@...> 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.khan@...<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. |
| Free embeddable forum powered by Nabble | Forum Help |