Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 终端上的内存分配第一次编译错误_C_Memory_Memory Management_Makefile_Malloc - Fatal编程技术网

C 终端上的内存分配第一次编译错误

C 终端上的内存分配第一次编译错误,c,memory,memory-management,makefile,malloc,C,Memory,Memory Management,Makefile,Malloc,我正在malloc实验室项目中工作,我需要找到效用和吞吐量的性能指标。我能够获得输出效率,但第一次执行时有一个问题 我已经给出了一组特定的文件,其中包括跟踪和其他文件,当我第一次尝试运行程序时,它会显示错误,但是当我第二次使用同一命令运行同一代码到多次时,我没有得到错误,输出是否正常?为什么第一次运行时显示错误?在malloc中分配内存或执行操作是否有问题 命令和第一次错误如下所示 enter code here @ubuntu:$ make enter code here gcc -Wall

我正在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
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.

现在,它没有显示错误,之后,如果我用所需的命令运行程序,它工作得很好,但它第一次显示错误

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


为了更好地理解,请在源代码中插入一些编译错误,并反复运行make命令,这样您就可以理解其中的区别。

错误来自一个名为mdriver.c的文件,该文件是我的教授提供的,我不必修改它,问题是我真的很困惑如何消除这些警告!!我试图更改make文件中的某些内容,但没有帮助@Dvlop尝试制作-s。它将超越印刷品。然后分享错误信息。到目前为止,我在你的帖子中找不到错误信息。尝试简化您的问题并再次发布。您有两个选项:修复产生警告的代码,禁用警告。如果您选择b,请准备好承担后果: