On Tue, Jun 18, 2013 at 11:17 PM, vijay nag <vijunag@xxxxxxxxx> wrote: > > (unsigned long*)foo++ too has the same effect but compiler warns us of > unused-value error. > Should it even warn us ? That does not have the same effect as what I wrote. That expression increments foo by the size of *foo, which in this case is sizeof(char). My expression increments foo by sizeof(unsigned long). Your expression, after incrementing foo, casts the result to unsigned long*. Nothing is done with the result of the cast, so it has no effect, so it is an unused value. The compiler warning is correct. Ian > On Wed, Jun 19, 2013 at 11:44 AM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote: >> >> On Tue, Jun 18, 2013 at 11:01 PM, vijay nag <vijunag@xxxxxxxxx> wrote: >> > >> > Consider the following expression >> > >> > char *foo = &bar; >> > ((unsigned long*)foo)++ >> >> I think the correct way to get the same effect these days is not what >> you suggested, but rather something like >> foo = (char *) (((unsigned long*)foo) + 1); >> >> Ian > >