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
  • As Hans says, ptr in main() is uninitialized. It could point anywhere, including an address where there is no RAM to store a value. Odds are, a garbage pointer happens to point to zero.

    Perhaps the ellipsis hides the initialization.

    There's no real reason to pass by reference in this case. Stylistically, I'd write

    U16 GetBaudRate (U8 uartNumber);

    This will also lead to smaller and faster code, particularly compared to using the 3-byte generic pointer to pass a 2-byte int.

    The "large" qualifier on the function makes me wonder. If this keyword changes the default pointer type for the parameter, and the caller is using a different memory model, the parameter might be confused without an explicit cast. But I'm feeling too lazy to test this hypothesis right now.

Reply
  • As Hans says, ptr in main() is uninitialized. It could point anywhere, including an address where there is no RAM to store a value. Odds are, a garbage pointer happens to point to zero.

    Perhaps the ellipsis hides the initialization.

    There's no real reason to pass by reference in this case. Stylistically, I'd write

    U16 GetBaudRate (U8 uartNumber);

    This will also lead to smaller and faster code, particularly compared to using the 3-byte generic pointer to pass a 2-byte int.

    The "large" qualifier on the function makes me wonder. If this keyword changes the default pointer type for the parameter, and the caller is using a different memory model, the parameter might be confused without an explicit cast. But I'm feeling too lazy to test this hypothesis right now.

Children
No data