工具/软件:TI C/C++编译器
大家好
我在AWR1642上使用ARM内核,编译器版本是16.9 v.1.LTS。 我想按如下所示对数组结构进行排序,但是,当我运行代码时,它会显示错误。 似乎qsort要访问无效区域。 你能告诉我什么是错的吗?
谢谢
西宁
#include <stdio.h>
#include <stdlib.h>
#include <Time.h>
typedef struct {
浮动价格;
浮动测试;
int id;
} order;
order list[10];
int i = 0;
int compare (const void * a,const void * b)
{
order *orderA =(order *) a;
order *orderB =(order *) b;
return (orderA-> price > orderB-> price)? 1:-1);
}
int main ()
{
srand((unsigned int)time(NULL));
printf ("排序前\n");
对于(i=0;i<10;i++){
list[i].price =(float) rand ()/(float)(RAND_MAX)* 10;
list[i].test = rand()%10;
list[I].id = i;
printf ("order id =%d price =%f Test =%f\n",list[i].id,list[i].price,list[i].test);
}
printf ("排序后\n");
int n;
qsort (列表,6,sizeof (顺序),比较);
对于(n=0;n<10;n++)
printf ("order id =%d price =%f Test =%f\n",list[n].id,list[n].price,list[n].test);
返回0;}
输出为:
排序之前
订单ID = 0价格= 6.34.7239万 测试= 8.0万
订单编号= 1价格= 1.64.7694万 测试= 3.0万
订单编号= 2价格= 5.4.9898万 测试= 5.0万
订单编号= 3价格= 8.67.4276万 测试= 4.0万
订单编号= 4价格= 4.47.0962万 测试= 0.0万
订单编号= 5价格= 6.62.5263万 测试= 6.0万
订单编号= 6价格= 3.48.2467万 测试= 9.0万
订单编号= 7价格= 6.93.0449万 测试= 9.0万
订单编号= 8价格= 5.34.1044万 测试= 6.0万
订单编号= 9价格= 5.46.556万 测试= 2.0万
排序后
ThreadType_Main中出现异常。
主手柄:0x0。
主堆栈底座:0x8019a40。
主堆栈大小:0x1000。
R0 = 0x804万 R8 = 0x8.0199万fc
R1 = 0x8.0199万e4 R9 = 0x804万
R2 = 0x0万c R10 = 0x0.871万
R3 = 0x0.871万 R11 = 0x0.0003万
R4 = 0x0.0005万 R12 = 0x804万
R5 = 0x0.333万 SP (R13)= 0x0801a9e8
R6 = 0x0万c LR (R14)= 0x0.0068万c3
R7 = 0x0.0006万 PC (R15)= 0x0.8738万
PSR = 0x000c01df
DFSR = 0x0万d IFSR = 0x0万
DFAR = 0x804万 IFAR = 0x0万
TI.SysBIOS.family.arm.exc.exception:line 205:e_dataAbort:PC = 0x0.8738万,LR = 0x0.0068万c3。
xdc.runtime.Error.raise:正在终止执行