Re: Where do pointers point to?

From: x-pander (ngclc_at_pitek.eu.org)
Date: 01/12/05


Date: Wed, 12 Jan 2005 21:50:59 +0100


>> void memset2(void *p, int c, int n)
>> {
>> while(n-->0) *((char *)p)++ = c;
>> }
>
> When my compiler considered this, it said
>
> "foo.c", line 4: warning: a cast does not
> yield an lvalue
>

yea, my bad, but that was not what the question was all about
let me change the implemetation to:

void memset2(void *p, int c, int n)
{
  while(n-->0) ((char *)p)[n] = c;
}

now it should be valid and the original question remains unchanged



Relevant Pages

  • Re: lvalues and rvalues
    ... int arr; ... This lvalue is of type int, ... pointer type) have both a value and a type. ... is not defined in the C standard. ...
    (comp.lang.c)
  • Re: gcc: pointer to array
    ... "lvalue" does not allow to be differentiated from. ... The integer constant 42 is <an expression with an object type or an incomplete type other than void>. ... the expression a is the int typed object and 42 is the int typed value. ... _function types_ (types that describe ...
    (comp.lang.c)
  • Re: Why is C Standard Code Example Invalid?
    ... jameskuyper> expressions that both read from and write to the member ... prohibit accessing the value of a structure object by way of an lvalue ... struct t *p; ... "int", but that lvalue is produced by operations on lvalues having ...
    (comp.std.c)
  • Re: using a method as an lvalue and "invalid lvalue in assignment" compilation error
    ... The result of a function call is not an lvalue. ... int *func ... a local object is bad. ...
    (comp.lang.c)
  • Re: union {unsigned char u[10]; ...}
    ... But character type is not a union. ... u.a is of type int. ... code above accesses the stored value of the object u.a using an lvalue ...
    (comp.lang.c)