gpt4 book ai didi

c - 为什么来自 "Learn C the hard way"的示例在 valgrind 中显示错误?

转载 作者:太空宇宙 更新时间:2023-11-04 01:03:00 24 4
gpt4 key购买 nike

我正在尝试学习 C 并正在阅读有关 valgrind 的信息。我有一个简单的 C 程序,如下所示,当我运行 valgrind 时它会提示

Conditional jump or move depends on uninitialised value

by 0x100000F50: main (ex5.c:9)
==4338== Uninitialised value was created by a stack allocation
==4338== at 0x1001F5BF8: __vfprintf (in /usr/lib/system/libsystem_c.dylib)

#include <stdio.h>

/* This is a comment. */
int main(int argc, char *argv[])
{
int distance = 100;

// this is also a comment
printf("You are %d miles away.\n", distance);

return 0;
}

错误从何而来?

最佳答案

对于一些库函数的实现来说,为了最有效,绕过 valgrind 将检查的一些规则是很常见的。

注意错误在__vfprintf (in/usr/lib/system/libsystem_c.dylib)

这并不总是一个问题。如果没有副作用(即使库也可能有错误)我会忽略它。

Valgrind 经常抑制无害的库警告;升级可能包括这个。

关于c - 为什么来自 "Learn C the hard way"的示例在 valgrind 中显示错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31190484/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com