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

what is the matter with the pointer?

hello all!

*.h
void Baudrate(unsigned int *ptr,unsigned char Uart_num) large;

*.c

void main(void)
{
...
*ptr = 1152;
Baudrate(ptr,1);
...
}
In the routine ,the var Baud( Baud = *ptr; )is not 1152 but 0x00.When changing the defintion : void Baudrate(unsigned int pp,unsigned char Uart_num) large;,and be called : Baudrate(1152,1);,the routine run well.
What is the wrong?

Parents
  • "unsigned int xdata *ptr;
    xdata unsigned int *ptr;"

    I believe the second example is obsolete syntax supported for backward compatibility. The new way of doing things is:

    char xdata * data ptr;

    Which is a pointer located in data space pointing to a char in xdata space. I think this makes things a bit easier as you only have to remember that the qualifier to the left of the '*' specifies the location of the object being pointed to and the qualifier to the right of the '*' specifies the location of the pointer.

    "Finally, to confuse you completely, answer what does next line do yourself:

    idata unsigned int xdata *ptr;"

    Yes, well, quite.

Reply
  • "unsigned int xdata *ptr;
    xdata unsigned int *ptr;"

    I believe the second example is obsolete syntax supported for backward compatibility. The new way of doing things is:

    char xdata * data ptr;

    Which is a pointer located in data space pointing to a char in xdata space. I think this makes things a bit easier as you only have to remember that the qualifier to the left of the '*' specifies the location of the object being pointed to and the qualifier to the right of the '*' specifies the location of the pointer.

    "Finally, to confuse you completely, answer what does next line do yourself:

    idata unsigned int xdata *ptr;"

    Yes, well, quite.

Children
  • hi,

    I just compiled next example:

    #include <reg51.h>
    
    void main(void)
    {
    idata char xdata *ptr;
    
    	ptr = 0x11;
    	*ptr = 0x22;
    	while (1);
    }
    The result assembly code is:
    ; ptr = 0x11;
    MOV      R0,#0x08
    MOV      @R0,#0x00
    INC      R0
    MOV      @R0,#0x11
    ; *ptr = 0x22;
    DEC      R0
    MOV      A,@R0
    MOV      R6,A
    INC      R0
    MOV      A,@R0
    MOV      DPL,A
    MOV      DPH,R6
    MOV      A,#0x22
    MOVX     @DPTR,A
    
    This shows that pointer is placed inside idata memory and points to xdata memory.

    Regards,
    Oleg

  • "This shows that pointer is placed inside idata memory and points to xdata memory."

    Sorry, I should have explained that. I didn't realise it was a question. The correct syntax would be:

    char xdata * idata ptr;