c - 无法增加指针

标签 c pointers

在代码部分中,stringData++ 行似乎根本没有增加指针。我有什么遗漏的吗?

bool WriteString(const char* stringData)
{
if(*stringData == '\0')
{
    return true;
}

/* Write a character at a time, only if transmitter is empty */
while (PLIB_USART_TransmitterIsEmpty(USART_ID_1))
{
    /* Send character */
    PLIB_USART_TransmitterByteSend(USART_ID_1, *stringData);

    /* Increment to address of next character */
    stringData++;

    if(*stringData == '\0')
    {
        return true;
    }
}
return false;
}

下面是默认的示例代码,可以使用

bool WriteString(void)
{
if(*appData.stringPointer == '\0')
{
    return true;
}

/* Write a character at a time, only if transmitter is empty */
while (PLIB_USART_TransmitterIsEmpty(USART_ID_2))
{
    /* Send character */
    PLIB_USART_TransmitterByteSend(USART_ID_2, *appData.stringPointer);

    /* Increment to address of next character */
    appData.stringPointer++;

    if(*appData.stringPointer == '\0')
    {
        return true;
    }
}
return false;
}

这里的“appData”只是一个结构实例,其中有一个 const char 指针。

最佳答案

只是为了确认代码没问题并且确实增加了指针。我错误地认为问题是因为指针没有增加。经过进一步调试,发现是硬件时序问题。详情请参阅上面的评论。

关于c - 无法增加指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41902250/

相关文章:

c - malloc 在 c 中但使用 2d 语法...编译没有答案

go - 如何在 Go 中复制接口(interface)值?

c - 将变量引用到现有数组

php - 使用 SWIG 创建 PHP C/C++ 扩展模块

c++ - 类方法返回指向具有模板的类成员的指针

在 OS X 上将动态 C 库 (dylib) 编译为程序

C程序: How to copy linked list to dynamic array?

c - 从 struct 分配给类型 struct * 时不兼容的类型

c - 如何使用 STM32 HAL_CAN 库生成格式正确的 TX CAN 帧?

c - 如何使用平方反比定律将光强度转换为线性值