【发布时间】:2018-10-31 19:50:31
【问题描述】:
好的,我收到了这个错误,我不知道如何解决它: 从 'signed char*' 到 'char*' 的无效转换
Dong (char*)ulStatsAsPercentage 没有帮助。
我在两个 sprintf 语句、每个语句的最后一个参数、第一个 sprintf 语句的 ulStatsAsPercentage 和第二个 sprintf 语句的 pxTaskStatusArray[ x ].ulRunTimeCounter 都收到此错误。
这是我的代码:
TaskStatus_t *pxTaskStatusArray;
volatile UBaseType_t uxArraySize, x;
unsigned long ulTotalRunTime, ulStatsAsPercentage;
ulStatsAsPercentage =
pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
pxTaskStatusArray = (TaskStatus_t*)pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
if( ulStatsAsPercentage > 0UL )
{
sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n",
pxTaskStatusArray[ x ].pcTaskName,
pxTaskStatusArray[ x ].ulRunTimeCounter,
ulStatsAsPercentage );//error at this line
}
else
{
/* If the percentage is zero here then the task has
consumed less than 1% of the total run time. */
sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n",
pxTaskStatusArray[ x ].pcTaskName,
pxTaskStatusArray[ x ].ulRunTimeCounter );//error here too
}
这是显示错误的控制台:
../L5_Application/main.cpp:181:60: error: invalid conversion from 'signed char*' to 'char*' [-fpermissive]
(char)ulStatsAsPercentage );
c:\users\alti\downloads\sjsu_dev\toolchain\arm-none-eabi\include\stdio.h:244:5: note: initializing argument 1 of 'int sprintf(char*, const char*, ...)'
int _EXFUN(sprintf, (char *__restrict, const char *__restrict, ...)
^
../L5_Application/main.cpp:181:60: warning: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'int' [-Wformat=]
(char)ulStatsAsPercentage );
^
../L5_Application/main.cpp:181:60: warning: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'int' [-Wformat=]
../L5_Application/main.cpp:189:74: error: invalid conversion from 'signed char*' to 'char*' [-fpermissive]
pxTaskStatusArray[ x ].ulRunTimeCounter );
^
c:\users\alti\downloads\sjsu_dev\toolchain\arm-none-eabi\include\stdio.h:244:5: note: initializing argument 1 of 'int sprintf(char*, const char*, ...)'
int _EXFUN(sprintf, (char *__restrict, const char *__restrict, ...)
^
任何帮助将不胜感激。
【问题讨论】:
-
你在哪一行得到错误?您能否编辑您的问题以用评论标记出来?然后还请复制粘贴完整和完整的错误输出,包括可能的信息说明。当然,请尝试创建一个Minimal, Complete, and Verifiable Example,或者至少告诉我们所有相关变量的声明。
-
pcWriteBuffer是如何定义的? -
并且强制转换
ulStatsAsPercentage不会改变任何东西,这不是所抱怨的(因为变量是整数类型)。 -
@Someprogrammerdude 我编辑了我的问题
-
@rici signed char *pcWriteBuffer