小编Dan*_*elJ的帖子

逻辑运算符在C语句中的return语句中

我最近一直在学习C,并且遇到了一些带有逻辑运算符的return语句,即

return(statement LOGIC statement);
Run Code Online (Sandbox Code Playgroud)

当语句评估为True或false(即1或0)时,LOGIC是一个逻辑运算符,如&&,|| 等等

这是一个很好的编码实践,因为对我来说似乎有点不对,使用if/else if语句会不会更好?

c logic coding-style return

3
推荐指数
2
解决办法
2070
查看次数

C程序从bash脚本运行时内存泄漏

我有一个C程序,它采用各种命令行参数,即

./Coupled arg1 argv2
Run Code Online (Sandbox Code Playgroud)

当我和valgrind一起运行时

valgrind ./Coupled arg1 arg2
Run Code Online (Sandbox Code Playgroud)

我没有内存泄漏.但是当我使用bash脚本,叫run形式,

arg1=thing1
arg2=thing2

./Coupled $thing1 $thing2
Run Code Online (Sandbox Code Playgroud)

然后跑

valgrind ./run
Run Code Online (Sandbox Code Playgroud)

我得到了很多仍然可以访问的内存泄漏.我已经读过,仍然可以访问内存泄漏不是一个大问题,但我很想知道为什么会发生这种情况?当用--leak-check=full --show-leak-kinds=all标志运行valgrind时,输出的一个示例位(完整的valgrind输出是多页长)

==4518== 1 bytes in 1 blocks are still reachable in loss record 1 of 269
==4518==    at 0x4C29BE3: malloc (vg_replace_malloc.c:299)
==4518==    by 0x46A3DA: xmalloc (in /usr/bin/bash)
==4518==    by 0x437219: make_variable_value (in /usr/bin/bash)
==4518==    by 0x438230: ??? (in /usr/bin/bash)
==4518==    by 0x43A35E: initialize_shell_variables (in /usr/bin/bash)
==4518==    by 0x41DD92: ??? (in /usr/bin/bash)
==4518==    by 0x41C482: main (in /usr/bin/bash)
Run Code Online (Sandbox Code Playgroud)

c bash memory-leaks

-2
推荐指数
1
解决办法
313
查看次数

标签 统计

c ×2

bash ×1

coding-style ×1

logic ×1

memory-leaks ×1

return ×1