[dgplug-users] A trivial C concept problem
Sumit Chakraborty
cool.sumitc at gmail.com
Fri Jul 3 00:15:43 PDT 2009
On Fri, Jul 3, 2009 at 10:24 AM, Shakthi Kannan <shakthimaan at gmail.com>wrote:
> Hi,
>
> --- On Fri, Jul 3, 2009 at 9:15 AM, abhishek
> sharma<emote2abhishek at gmail.com> wrote:
> | int *p=c; //For this code
> | gcc compiles normally without any error or problem
> \--
>
> This is correct.
>
> ---
> | int c[5]={1,2,3,4,5};
> |
> | int *p;
> |
> | *p=c; //GCC gives a typecast
> \--
>
> It should be 'p = c'. On the left-hand side of the assignment there
> should be an address or LVALUE. On the right-hand side of the
> assignment you should have a value or RVALUE. When you do *p on the
> left-hand side of the assignment, you are dereferencing the address or
> pointer, to get a RVALUE. Hence, the error.
>
> 1. Don't use // comments in C coding style.
>
> 2. Initialize your pointer variables, or assign NULL to them.
>
> int *p = NULL;
>
> SK
>
> --
>
I agree with Shakthi.
When you are doing int *p=c, the compiler does two things:
1. int *p //declare the variable p as type int *
2. p=c // store the base address of the variable a
So instead of *p=c, your code should feature p=c.
Thanks and Regards
Sumit Chakraborty
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dgplug.org/pipermail/users-dgplug.org/attachments/20090703/9e279f3e/attachment-0002.htm>
More information about the Users
mailing list