简体   繁体   English

将函数的返回值强制转换为指针类型

[英]Typecasting return value of function to pointer type

I have following code: 我有以下代码:

#define PLL0STAT        (*((volatile unsigned short*) 0xE01FC088))
// Function Prototypes
void diaplayInRow1WithPosition(unsigned char* data, unsigned char position);
unsigned char convertLowerNibbleToASCIIValue(unsigned char data);
void func1 (void)
{
    unsigned char temp = (unsigned char) PLL0STAT; // Interested in last byte only
    temp = convertLowerNibbleToASCIIValue(temp);
    diaplayInRow1WithPosition(&temp,15);
}

instead of above code, I thought I will replace the last line with one step and used below statement 而不是上面的代码,我想我将一步替换掉最后一行,并在下面的语句中使用

diaplayInRow1WithPosition(((unsigned char*)convertLowerNibbleToASCIIValue(temp3)),15);

But the code compiles correctly, but nothing is displayed in LCD. 但是代码可以正确编译,但是LCD上没有任何显示。 Not able to makeout the reason. 无法找出原因。 Typecasting is done correctly for the pointer I thought. 对于我认为的指针,类型转换正确完成。 Is there any other issue? 还有其他问题吗?

The original code is already fine. 原始代码已经可以了。 Why you are trying to turn it into an unreadable one-liner, I have no idea. 为什么你试图将其变成难以理解的单线,我不知道。 You will not gain performance, you will achieve nothing, you only obfuscate the code. 您将不会获得性能,您将一无所获,仅混淆代码。 As we can see from the need to ask this question: you have made your code unreadable even to yourself. 正如我们从问这个问题的需要可以看到的那样:您甚至使自己无法读取代码。 Just leave the code as it was. 只需保留原样的代码即可。

The actual bug comes from the strange cast to (unsigned char*) that you have added. 实际的错误来自您添加的奇怪的强制转换为(unsigned char*)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM