This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Advice on Pointer arithmetic please?

Could anyone enlighten me on pointer arithmetic please?

Assigning a constant is fine, but a warning is generated when using a variable. (The code does do what I expect though.)

The warning is :
'long' converted to 'xhuge' pointer

void Test()
{
long x;
char xhuge *ptr;
x=2;

ptr = 0x80000 + 0x01;   // no-warning
ptr = 0x80000 + x;      // warning generated
x = 0x80000;
ptr += x;		// no-warning
ptr = x;                // warning generated
}


Andy

Parents
  • Explicit cast to a pointer type will suppress the warning:

    ptr = (char xhuge*)(0x80000 + x);
    
    By the way,
    ptr += x;
    
    should not generate any warnings, since the operation of adding an integer to a pointer is defined in the language (see C language reference.)

    - mike

Reply
  • Explicit cast to a pointer type will suppress the warning:

    ptr = (char xhuge*)(0x80000 + x);
    
    By the way,
    ptr += x;
    
    should not generate any warnings, since the operation of adding an integer to a pointer is defined in the language (see C language reference.)

    - mike

Children