当我学习C语言时,老师终日告诉我:"不要使用goto,这是一个坏习惯,它很丑,很危险!" 等等.
那么,为什么一些内核程序员会使用goto,例如在这个函数中,它可以用一个简单的替换
while(condition) {}
Run Code Online (Sandbox Code Playgroud)
要么
do {} while(condition);
Run Code Online (Sandbox Code Playgroud)
我无法理解.在某些情况下使用goto而不是while/ do- 更好while吗?如果是这样,为什么?
如果我在.h文件中定义我的函数会发生什么
extern int returnaint(void);
Run Code Online (Sandbox Code Playgroud)
,在相关的.c文件中定义它
inline int returnaint(void) {
return 1;
}
Run Code Online (Sandbox Code Playgroud)
并将标题包含在另一个.c文件中并使用该函数?当我单独编译事物时,为每个.c文件创建一个目标文件然后链接它们,包括内联函数,或者会发生什么?
我知道编译器可以忽略inline,但如果它在这种情况下不忽略它怎么办?
我真的无法进入makefile.在以前的项目中,我在Makefile中硬编码了所有编译任务:
all: compile_a compile_b compile_c
compile_a:
${CC} ${CFLAGS} ${A_SRC} -o ${A_OUT}
Run Code Online (Sandbox Code Playgroud)
等等.
但是由于最新的项目比以前的每个项目都有更多的文件,我想写更好的make任务,当然还有LESS角色因为make对我的眼睛不太友好(这让他们受苦)!:-P
我想要的是:
make projectname或者make all,你知道吗?)%.o: %.c语法的东西,但是没有真正得到它)项目结构是:
bin (binary goes here!)
src
some
directories
are
here
Run Code Online (Sandbox Code Playgroud)
我不知道我是否需要目录文件的目录,我把它们放进去./bin,我觉得这很好,不是吗?
也许我只需要一个能用简单的词语解释它的人!
编辑:有人指出,没有真正的问题,所以在这里:
bin/(filename).o.o在不知道名字的情况下链接'bin /'中的所有文件也许这有帮助.
我有这样的设置:
/Makefile
/foo/Makefile
/foo/bar/Makefile
/foo/baz/Makefile
Run Code Online (Sandbox Code Playgroud)
顶级Makefile包含一个调用的任务/foo/Makefile.此生成文件会在生成文件的子目录的列表(bar,baz在本例中).对于每个子目录,它调用Makefile:
$(SUB_DIRS):
$(MAKE) -C $@
Run Code Online (Sandbox Code Playgroud)
这对all任务来说是好的.但如果我想做别的事,我就会陷入困境.是否有可能将目标传递给子makefile列表?例如:
$(SUB_DIRS):
$(MAKE) -C $@ <task>
clean: $(SUB_DIRS)-clean # or something?
Run Code Online (Sandbox Code Playgroud)
或者我的整个概念是错的?
是有办法有一个pre-commit钩子,其自动格式化代码(例如用astyle),但并没有破坏的部分提交吗?
工作流程:
# edit a file.txt
git add -p file.txt
# add one chunk, but not another
git commit -m 'a message'
[PRE_COMMIT_HOOK] Formatting source code
git status
# the "another" chunk is still not added
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果你git add在预提交钩子里面做了一个,这是在脚本格式化源代码之后需要的,那么也添加了"另一个"块.但我不希望这样.
有没有办法实现这个目标?
我有一个字符串数组,我想只选择这些作为文件路径的字符串:
我的路径是"~/dlds/some_file.ics"其中~/dlds的一个符号链接到~/archive/downloads我的系统上.该文件具有以下权限:
-rw-r--r--
Run Code Online (Sandbox Code Playgroud)
我的代码(我尝试了几种变体):
ARGV.select do |string|
File.file? string # returns false
Pathname.new(string).file? # returns false
Pathname.new(string).expand_path.file? # returns false
end
Run Code Online (Sandbox Code Playgroud)
我不知道还有什么可以尝试的.
我正在运行Ruby 2.2.0或2.2.2.
我写了这段无辜的代码,导致了这样一个邪恶的错误:
static char * prefixed( char * pref, char *str ) {
size_t newalloc_size = sizeof(char) * (strlen(pref) + strlen(str));
char * result = (char*) malloc( newalloc_size );
[...]
Run Code Online (Sandbox Code Playgroud)
debug(cgdb)的输出:
Breakpoint 1, prefixed (pref=0x401345 "Env: ", str=0x4012b5 "Home") at ./src/backend/os/env.c:77
(gdb) s
(gdb) p newalloc_size
$1 = 9
(gdb) s
envtest: malloc.c:2368: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >=
(unsigned long)((((__builtin_offsetof …Run Code Online (Sandbox Code Playgroud) 我有以下文件夹结构:
.
??? include
? ??? ctset
? ??? hashtable.h
? ??? set.h
??? src
??? hashtable
??? hashtable.c
Run Code Online (Sandbox Code Playgroud)
在hashtable.c包含中#include "ctset/hashtable.h",但YCM一直告诉我它不知道我在标题中定义的类型并在源代码中使用.
我.ycm_extra_conf.py几乎是默认的一个调整:
# This file is NOT licensed under the GPLv3, which is the license for the rest
# of YouCompleteMe.
#
# Here's the license text for this file:
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, …Run Code Online (Sandbox Code Playgroud) 我确定它没有,但也许它里面有黑魔法,所以这是我的问题:
如果我有这样的结构:
struct mystr {
char * strp,
unsigned int foo,
};
Run Code Online (Sandbox Code Playgroud)
我为它分配内存,并希望稍后发布.我该做什么
free(mystr_var->strp);
free(mystr_var);
Run Code Online (Sandbox Code Playgroud)
或者是最后一行,free()函数是否遵循指针并释放它们两个?
我在 debian Jessie 上使用 mod_proxy_fcgi 和 apache 2.4,我的 C++ 应用程序使用 libfcgipp 执行 ServerSentEvents。
我的问题是,那个 apache 仍然缓冲我的响应数据。我通过使用 wireshark 确认它没有被 libfcgipp 库缓冲:通过 启动 fcgi 应用程序后spawn-fcgi,数据会尽快发送到 apache 网络服务器。但是在我的浏览器中(我用于测试,稍后会有一个 C++ 客户端)它只在我“杀死”/关闭服务器应用程序中的发送请求后才会显示。
所以我假设我需要禁用 apache 或 mod_proxy_fcgi(或两者)的缓冲。但是我找不到有关如何执行此操作的适当文档。
c ×6
makefile ×2
malloc ×2
apache ×1
apache2.4 ×1
buffer ×1
cgdb ×1
fastcgi ×1
formatting ×1
free ×1
git ×1
githooks ×1
gnu-make ×1
goto ×1
header ×1
header-files ×1
inline ×1
linker ×1
linux ×1
linux-kernel ×1
loops ×1
mod-proxy ×1
path ×1
pathname ×1
pointers ×1
python ×1
ruby ×1
sigabrt ×1
struct ×1
vim ×1
vim-plugin ×1