【发布时间】:2018-10-23 08:44:35
【问题描述】:
我想检查一个数组是否在 C 中按 acs 或 desc 顺序排序。 这是使用 mpicc -Wall -o file file.c 编译的结果,因为我在后面的代码中使用了 MPI 库。
mypractice1.c: In function ‘isSorted’:
mypractice1.c:38:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
/usr/bin/ld: unrecognised emulation mode: ypractice1
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu i386linux elf_l1om elf_k1om i386pep i386pe
collect2: error: ld returned 1 exit status
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <mpi.h>
//Function to check the order
int isSorted(int size, int array[]) {
if(size<=1)
return 1; //is ordered
int i;
for(i = 1; i < size; i++){
if(array[i] >= array[i-1])
return 1; //is Sorted ascending
else if (array[i]< array[i-1])
return 2; //is sorted descending
else return 0; //is not ordered
}
}
我该如何解决这个错误?
【问题讨论】:
-
请说明您看到的问题。现在问题说“编译得不是很好”,但是您可以通过引用编译错误消息来使其更清楚。还请显示编译器在哪一行抱怨(例如,如果它说“第 15 行”,请在代码中添加注释“第 15 行在这里”,这样人们会很容易看到它)。
-
int *orden = isSorted(num_elements_per_proc, buffer);- orden 是一个指向 int 的指针,isSorted 返回 int -
编译不好是什么意思?它要么编译,要么不编译。
-
randomNumbers()不返回任何内容。尝试使用-Wall编译并首先修复所有警告。 -
这就是分段错误。
标签: c arrays sorting pointers mpi