帮我解释一下这个C语言程序?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了帮我解释一下这个C语言程序?相关的知识,希望对你有一定的参考价值。
意思大概是接收用户输入(用户任意输入9个整数),然后在main中调用使用ARM汇编编写的函数(在该函数中完成对这9个整数的排序功能),然后再在C程序main函数中输出这9个排好顺序的整数,帮我解释一下这个C语言程序的每一步,写在每一步右边,汇编程序不会解释就算了。
#include <stdio.h>
extern void sort(int *srcarray,int number);
int main(void)
int i=0;
int num=0;
int *arr1=NULL;
int *arr2;
while(num <= 0)
printf("please enter the number of elements:\n");
scanf("%d",&num);
if(num > 0)
break;
arr1 = (int *)malloc(num*sizeof(int));
if(NULL == arr1)
printf("malloc failed!\n");
exit(-1);
arr2=arr1;
printf("please enter the elements:\n");
for(i = 0; i<num; i++)
scanf("%d", arr1+i);
sort(arr1,num);
printf("the result is:\n");
for(i = 0; i<num; i++)
printf("%d:\t%d\n", i, *(arr2+i));
return 0;
汇编程序:
AREA SORTED,CODE,READONLY
EXPORT sort
sort:
SUBS R1,R1,#1
loop: MOV R7,R1
MOV R4,R0
loop2: LDR R5,[R4]
LDR R6,[R4,#4]!
CMP R5,R6
STRGT R5,[R4]
STRGT R6,[R4,#-4]
SUBS R1,R1,#1
BNE loop2
MOV R1,R7
SUBS R1,R1,#1
BNE loop
MOV PC,LR
AREA SORTED,CODE,READONLY
EXPORT sort
sort:
SUBS R1,R1,#1
loop: MOV R7,R1
MOV R4,R0
loop2: LDR R5,[R4]
LDR R6,[R4,#4]!
CMP R5,R6
BLE skip
STR R5,[R4]
STR R6,[R4,#-4]
skip: SUBS R1,R1,#1
BNE loop2
MOV R1,R7
SUBS R1,R1,#1
BNE loop
MOV PC,LR
extern void sort(int *srcarray,int number); /*定义一个外部函数*/
int main(void)
int i=0;
int num=0;
int *arr1=NULL;
int *arr2;
/*以下是输入要排序的数据的个数*/
while(num <= 0)
printf("please enter the number of elements:\n");
scanf("%d",&num);
if(num > 0) /*确定数据个数必须大于0个,即num必须为正整数*/
break; /*如果num为正整数,就退出循环*/
/*到此*/
arr1 = (int *)malloc(num*sizeof(int)); /*申请内存空间,大小为:num个int类型*/
if(NULL == arr1)/*如果申请空间失败,输出错语信息,退出*/
printf("malloc failed!\n");
exit(-1); /*退出*/
arr2=arr1;/*将申请到的空间首地址赋给另一指针arr2,以备后面输出结果用*/
/*以下为输入num个整数*/
printf("please enter the elements:\n");
for(i = 0; i<num; i++)
scanf("%d", arr1+i);/*此处:arr1+i为第i个数据的地址*/
/*输入结束*/
sort(arr1,num);/*将输入的num个数据排序*/
/*以下是输出排序后结果*/
printf("the result is:\n");
for(i = 0; i<num; i++)
printf("%d:\t%d\n", i, *(arr2+i));
/*例:输出格式:
1: 3
2: 4
*/
return 0;/*返回*/
参考技术B #include <stdio.h> --头文件
extern void sort(int *srcarray,int number); --声明外部函数
int main(void) --主函数
int i=0;
int num=0;
int *arr1=NULL;
int *arr2;
while(num <= 0) 输入要排序的数据的个数
printf("please enter the number of elements:\n");
scanf("%d",&num);
if(num > 0) 如果是正数就往下执行,是非正数就一直要求输入直到正
break;
arr1 = (int *)malloc(num*sizeof(int));
if(NULL == arr1)
printf("malloc failed!\n");
exit(-1);
arr2=arr1;
printf("please enter the elements:\n");
for(i = 0; i<num; i++)
scanf("%d", arr1+i);
sort(arr1,num);
printf("the result is:\n");
for(i = 0; i<num; i++)
printf("%d:\t%d\n", i, *(arr2+i));
return 0;
本回答被提问者采纳
Graphite:帮我解释一下whisper-info.py的输出
【中文标题】Graphite:帮我解释一下whisper-info.py的输出【英文标题】:Graphite: Help me interpret the whisper-info.py output 【发布时间】:2014-10-15 05:04:48 【问题描述】:我一直在尝试从 Whisper-info.py 输出中弄明白,这对我来说似乎有点神秘。
目前这是我的设置:
storage-schema.conf
[carbon]
pattern = ^carbon\.
retentions = 60:90d
[stats]
pattern = ^stats.*
retentions = 30s:6h,1min:30d,10min:360d,30min:720d,1h:1825d,1d:1825d
[everything_else]
pattern = .*
retentions = 30s:6h,1min:30d,10min:360d,30min:720d,1h:1825d,1d:1825d
storage-aggregation.conf
[min]
pattern = \.lower$
xFilesFactor = 0.1
aggregationMethod = min
[max]
pattern = \.upper(_\d+)?$
xFilesFactor = 0.1
aggregationMethod = max
[sum]
pattern = \.sum$
xFilesFactor = 0
aggregationMethod = sum
[count]
pattern = \.count$
xFilesFactor = 0
aggregationMethod = sum
[count_legacy]
pattern = ^stats_counts.*
xFilesFactor = 0
aggregationMethod = sum
[default_average]
pattern = .*
xFilesFactor = 0.3
aggregationMethod = average
我前面有 statsd,非常少 localConfig.js
graphitePort: 2003,
graphiteHost: "127.0.0.1",
port: 8125,
flushInterval: 30000,
现在我向 stasd 发送一个数据包到一个全新的指标
echo "alex.foo:1|c" | nc -w1 -u 127.0.0.1 8125
这是whisper-info.py的输出:
# whisper-info.py /opt/graphite/storage/whisper/stats/alex/foo.wsp
maxRetention: 604800
xFilesFactor: 0.300000011921
aggregationMethod: average
fileSize: 120988
Archive 0
retention: 604800
secondsPerPoint: 60
points: 10080
size: 120960
offset: 28
当我显然有更多的保留设置时,为什么只有一个存档?我的架构规则不正确吗?输出的含义是什么? size 是文件大小吗?偏移量?
感谢您抽出宝贵时间回答!
【问题讨论】:
【参考方案1】:我发现问题出在我的 storage-schema.conf 文件的语法上。我找到了这个方便的工具 validate-storage-schemas.py(在 /opt/graphite/bin/ 中找到),输出非常清晰。
./validate-storage-schemas.py
Loading storage-schemas configuration from default location at: '/opt/graphite/conf/storage-schemas.conf'
Section 'carbon':
OK
Section 'stats':
- Error: Section 'stats' contains an invalid retention definition ('30s:6h,1min:30d,10min:360d,30min:720d,1h:1825d,1d:1825d')
Lower precision archives must cover larger time intervals than higher precision archives (archive4: 157680000 seconds, archive5: 157680000 seconds)
OK
Section 'everything_else':
- Error: Section 'everything_else' contains an invalid retention definition ('30s:6h,1min:30d,10min:360d,30min:720d,1h:1825d,1d:1825d')
Lower precision archives must cover larger time intervals than higher precision archives (archive4: 157680000 seconds, archive5: 157680000 seconds)
OK
现在,如果我对文件进行耳语信息,它们就有意义了:
root@graftwo:/opt/graphite# Whisper-info.py /opt/graphite/storage/whisper/local/test/diceroll.wsp 最大保留:172800000 xFilesFactor:0.300000011921 聚合方法:平均 文件大小:2113528
Archive 0
retention: 21600
secondsPerPoint: 30
points: 720
size: 8640
offset: 88
Archive 1
retention: 2592000
secondsPerPoint: 60
points: 43200
size: 518400
offset: 8728
Archive 2
retention: 31104000
secondsPerPoint: 600
points: 51840
size: 622080
offset: 527128
Archive 3
retention: 62208000
secondsPerPoint: 1800
points: 34560
size: 414720
offset: 1149208
Archive 4
retention: 157680000
secondsPerPoint: 3600
points: 43800
size: 525600
offset: 1563928
Archive 5
retention: 172800000
secondsPerPoint: 86400
points: 2000
size: 24000
offset: 2089528
我仍然想知道两件事: - 为什么 carbon-cache 没有因语法错误而失败? - 这个硬默认来自哪里? - 这个偏移量是什么?
谢谢!希望这对其他人有帮助
【讨论】:
以上是关于帮我解释一下这个C语言程序?的主要内容,如果未能解决你的问题,请参考以下文章
有谁能否帮我解释一下C语言中的volatile关键字,最好是要有程序例子的。谢谢啊!!
帮我解释一下这个小小程序吧,菜鸟刚学,真心不懂呀,,,,在线等,谢谢各位啦~~