向c *添加从const char *到char *的无效转换" [英] Adding to c* invalid conversion from const char* to char*"

查看:139
本文介绍了向c *添加从const char *到char *的无效转换"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Arduino的WiServer.h文件中具有以下功能.

I have the function below in a file called WiServer.h for Arduino.

GETrequest(uint8* ipAddr, int port, char* hostName, char* URL);

现在的问题是,我需要将一个int值(设置1)连接到char* URL参数,例如下面的示例.

Now the problem is I need to concatenate an int value (setting1) to the char* URL parameter like the below for example.

"twittermood.php?status=sendTweet&setting1="+setting1

我得到一个错误:

从const char *到char *的无效转换

invalid conversion from const char* to char*

我该如何解决?

推荐答案

您已经获得了不错的通用C ++建议,但是对于8位AVR微控制器上Arduino的特殊情况,我认为您需要特定于平台的建议:

You've gotten decent generic C++ advice, but for the special case of Arduino on an 8-bit AVR microcontroller I think you need platform-specific advice:

Arduino运行时提供了一个 String 对象. 这些示例.

The Arduino runtime provides a String object. Your question is probably covered by these examples.

由于Arduino上的RAM空间非常有限,通常使用特殊属性将常量字符串放入闪存(本质上是ROM)中,这需要不同的指令来访问.使用GCC构建的AVR代码通常建立在 AVR Libc 的基础上,该库支持运行混合使用常量字符串和RAM字符串.您必须在代码中明确显示并选择正确的操作.这至少需要对C字符串如何工作以及指针如何工作有基本的了解.我不确定Arduino字符串会自动提供多少这种技巧,但是如果没有这种技巧,您的所有字符串常量最终都会在启动时复制到RAM中,并始终占用这些宝贵的字节.

Because of the very limited RAM space on Arduino it is common to use special attributes to put constant strings in flash (essentially ROM) which requires different instructions to access. AVR code built with GCC is typically built on top of AVR Libc which has support for operating on a mix of constant strings and RAM strings. You must be explicit in your code and choose the right operations. This requires at least a basic understanding of how C strings work and how pointers work. I'm not sure how much of this cleverness is automatically provided by the Arduino String, but without this cleverness all of your string constants will end up copied into RAM at boot and will take up those precious bytes all the time.

如果RAM空间成为问题,或者您正在使用AVR应用程序进行广泛的字符串操作,则需要学习如何使用PGM空间操作(可以在Flash中处理只读字符串的字符串函数)和

If RAM space becomes a problem or you are working on an AVR application that does extensive string manipulation you need to learn how to use the mix of PGM Space operations (string functions that can work on read-only strings in flash) and regular C-style RAM-based string operations.

这篇关于向c *添加从const char *到char *的无效转换"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆