This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] MSP430FR2355:难以处理指向数组的指针返回分配?

Guru**** 2387080 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1189598/msp430fr2355-struggling-with-pointer-return-assignment-to-array

器件型号:MSP430FR2355

ok....no不知道我在这里错过了什么,但这家酒店的失败是不可避免的…

当我尝试分配 test =时、编译器会发出 hates  

返回函数工作正常,我已使返回变量为静态变量,以便不会丢失范围....测试是一个数组,所以我希望测试与我执行&test[0]时相同...我在这里缺少什么?

uint8_t test[6];

  for (uint8_t k = 0; k < NO_ADC_CH; k++)
  {
	  test = hex2Ascii(&stream[k]);
	  test[4] = '\r';
	  test[5] = '\n'; //new line
	  HAL_UART_Transmit_IT(&huart2, test, sizeof(test));
  }


char*hex2Ascii(uint16_t *val)
{
    unsigned char d;
    static char buff[4];

    buff[0] = (char)((d = (*val >> 12)) > 9 ? ('A' + d - 10) : ('0' + d));
    buff[1] = (char)((d = ((*val >> 8) & 0xf)) > 9 ? ('A' + d - 10) : ('0' + d));
    buff[2] = (char)((d = ((*val >> 4) & 0xf)) > 9 ? ('A' + d - 10) : ('0' + d));
    buff[3] = (char)((d = (*val & 0xf)) > 9 ? ('A' + d - 10) : ('0' + d));
    return buff;
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Steve、

    不能将两个数组设置为彼此相等。 您必须使用 for 循环将内容从一个数组手动复制到另一个数组、或者您可以使用诸如 memcpy (memcpy (array1、array2、sizeof (array1))等更优化的函数。  

    Amruta