pointer arithmetic for alignment on short or int boundry

Burak Serdar bserdar@nc.rr.com
Sun Sep 21 14:55:00 GMT 2003


Try

a = (char *)((unsigned)(a + 1) & (unsigned)((char*) -2))

You can only add or subtract pointers for pointer arithmetic.

Andy Howell wrote:
> I need to calculate an address on a short or int boundry. For some 
> reason this is not working:
> 
> char *a;
> 
> a = (a + 1) & ((char*) -2));
> 
> Gcc 3.3 on Solaris complains:
> 
> error: invalid operands of types `char*' and `
>    char*' to binary `operator&'
> 
> Why shouldn't I be able to mask off the low bit?
> 
> Thanks,
> 
>     Andy
> 
> 



More information about the Gcc-help mailing list