Pointer subtractions

>
> hi vijay,
>           please can you tell me why ?
>
>        struct {
>              int i;
>              char j;
>              long k;
>         }b;
>     when we are trying &b.k - &b, it is giving error.
>

Section A6.6, Pointers and Integers, of K&R-II says:

    An expression of integral type may be added to or subtracted
from a pointer; in such a case the integral expression is converted
as specified in the discussion of the addition operator (A7.7)

    Two pointers to object of the *same type*, in the same array,
may be subtracted; the result is converted to an integer as specified
in the discussion of the subtraction operator (A7.7)


POINTS:

*   Because of the second rule, the expression &b.k - &b is invalid
    as both the pointers are not of the same type.

*   We can cast the second operand to an int or size_t to remove the
    error.

        &b.k - (size_t) &b;

    This complies to rule stated in the paragraph one.  The result is
    useless, though, as it does not give the required offset of the
    member, k.  Use the following statement, instead:

        (size_t) &b.k - (size_t) &b;


        PS:  Notice that the expression, (int) &b.k - &b,
             is an error.