我可以接受在Microchip的C18

我可以接受在Microchip的C18

本文介绍了我可以接受在Microchip的C18 RAM和ROM指针的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我宣布,接受为const char * 函数,我传递一个字符串,我得到一个

When I declare a function that accepts const char* and I pass a string literal, I get a

警告:[2066]在分配类型限定符不匹配

因为字符串文字 ROM为const char * 。这是同样的周围的其他方法。

because string literals are rom const char*. It's the same the other way around.

虽然在PIC是哈佛架构中,存储器被映射到一个连续的地址空间,因此从理论上讲应当能够同时支持的RAM和ROM的指针相同的方式。也许我必须使用ROM指针,因为他们是24位,而RAM指针是16位的。

Though the PIC is Harvard architecture, the memory is mapped into one contiguous address space, so theoretically it should be possible to support both ram and rom pointers the same way. Probably I have to use rom pointers because they are 24 bit while ram pointers are 16 bit.

然而,就铸造了为const char * 常量ROM的char * 不起作用。

However, just casting a const char* to a const rom char* does not work.

推荐答案

不幸的是,这是Microchip的C18编译器的固有限制。的在C18的指针可以指向ROM或RAM,但不能同时使用。

Unfortunately, this is an inherent limitation of the Microchip C18 compiler. A pointer in C18 can point to either ROM or RAM, but not both.

这就是为什么你会发现重复的职能在例如ROM和RAM操作 Microchip应用库:

This is why you will find duplicated functions for ROM and RAM operations in e.g. the Microchip Application Libraries:

BYTE* TCPPutString(TCP_SOCKET hTCP, BYTE* Data);
ROM BYTE* TCPPutROMString(TCP_SOCKET hTCP, ROM BYTE* Data);

高科技PICC-18编译器在运行时确定合适的地址空间,允许更灵活的使用指针。这是我赞成PICC-18的抛弃C18的原因之一。

The Hi-Tech PICC-18 compiler has the appropriate address space determined at runtime, which allows for more flexible pointer usage. This is one of the reasons I ditched C18 in favour of PICC-18.

查看答案和约翰寺庙的获得更深入的了解。

See the answers to this question and John Temples' Comparison of Hi-Tech PICC-18 and MPLAB C18 for more insight.

这篇关于我可以接受在Microchip的C18 RAM和ROM指针的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 15:19