内存分配首次在终端上编译错误

时间:2014-10-29 00:57:44

标签: c memory memory-management makefile malloc

我正在开发一个malloc实验室程序,我需要找到效用和吞吐量的性能指标。我能够获得输出效率,但第一次执行时有一个问题。

我已经给出了包含跟踪和其他文件的特定文件集,当我第一次尝试运行程序时它显示错误但是当我第二次使用相同的命令运行相同的代码时多次我没有得到错误和输出很好吗?为什么它在第一次运行时显示错误?在malloc中分配内存或执行操作有什么问题吗?

命令和第一次错误如下,

enter code here
@ubuntu:$ make

当我第一次运行时,我收到的错误如下,

enter code here
gcc -Wall -O2 -m32   -c -o mdriver.o mdriver.c
mdriver.c: In function ‘remove_range’:
mdriver.c:438:9: warning: variable ‘size’ set but not used [-Wunused-but-set-variable]
 int size;
     ^
mdriver.c: In function ‘read_trace’:
mdriver.c:498:11: warning: ignoring return value of ‘fscanf’, declared with attribute   warn_unused_result [-Wunused-result]
 fscanf(tracefile, "%d", &(trace->sugg_heapsize)); /* not used */
       ^
mdriver.c:499:11: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(tracefile, "%d", &(trace->num_ids));     
       ^
mdriver.c:500:11: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(tracefile, "%d", &(trace->num_ops));     
       ^
mdriver.c:501:11: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(tracefile, "%d", &(trace->weight));        /* not used */
       ^
mdriver.c:524:12: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(tracefile, "%u %u", &index, &size);
        ^
mdriver.c:531:12: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(tracefile, "%u %u", &index, &size);
        ^
mdriver.c:538:12: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(tracefile, "%ud", &index);
        ^
gcc -Wall -O2 -m32   -c -o mm.o mm.c
mm.c:780:13: warning: ‘mm_check’ defined but not used [-Wunused-function]
static int mm_check(void)
         ^
gcc -Wall -O2 -m32   -c -o memlib.o memlib.c
gcc -Wall -O2 -m32   -c -o fsecs.o fsecs.c
gcc -Wall -O2 -m32   -c -o fcyc.o fcyc.c
gcc -Wall -O2 -m32   -c -o clock.o clock.c
gcc -Wall -O2 -m32   -c -o ftimer.o ftimer.c
gcc -Wall -O2 -m32 -o mdriver mdriver.o mm.o memlib.o fsecs.o fcyc.o clock.o ftimer.o

我再次运行相同的命令

enter code here
@ubuntu:$ make
make: `mdriver' is up to date.

现在它显示没有错误,之后如果我使用所需的命令运行程序它完全正常,但它第一次显示错误?

1 个答案:

答案 0 :(得分:0)

您的来源没有错误。有很多警告。即使源有警告,也会生成对象和可执行文件。在makefile中,如果时间戳保持不变,则不会重新编译文件。

为了更好地理解,请在源代码中输入一些编译错误,然后一次又一次地运行make命令,然后就可以了解其中的差异。