根据System V X86-64 ABI,应用程序中的函数调用使用以下寄存器序列来传递整数参数:
rdi, rsi, rdx, rcx, r8, r9
Run Code Online (Sandbox Code Playgroud)
但是系统调用参数(除了系统调用号)在另一个寄存器序列中传递:
rdi, rsi, rdx, r10, r8, r9
Run Code Online (Sandbox Code Playgroud)
为什么内核使用r10而不是rcx第四个参数?它是否以某种方式与rcx未被保留的事实有关r10?
exit(3)表示stdio流被冲洗和关闭.但没有什么能说明C++特定的ofstream对象.
标准是否保证ofstream对象也被正确刷新和关闭,或者我是否必须以某种方式将退出条件传播到那里main()并在return那里销毁所有自动流?
假设我有一个以 开头的片段着色器#version 120和一个以#version 150 compatibility. 这种组合似乎适用于 AFAICT,但它是否违反 OpenGL 或 GLSL 规范?我找不到任何讨论这个问题的信息。如果确实没有,我应该将其视为“未禁止”还是“未批准”?
我制作了一个简单的模块,可以在加载时打印 GDT 和 IDT。当它完成工作后,就不再需要它并且可以卸载。但如果它返回负数以停止加载,insmod则会抱怨,并且错误消息将记录在内核日志中。
内核模块如何优雅地卸载自身?
考虑一个简单的C程序:
#include <stdio.h>
int main()
{
puts("Hello");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
使用GDB运行它,LD_BIND_NOW=1为简单起见,我可以观察到以下内容:
$ gdb -q ./test -ex 'b main' -ex r
Reading symbols from ./test...done.
Breakpoint 1 at 0x8048420
Starting program: /tmp/test
Breakpoint 1, 0x08048420 in main ()
(gdb) disas
Dump of assembler code for function main:
0x0804841d <+0>: push ebp
0x0804841e <+1>: mov ebp,esp
=> 0x08048420 <+3>: and esp,0xfffffff0
0x08048423 <+6>: sub esp,0x10
0x08048426 <+9>: mov DWORD PTR [esp],0x8048500
0x0804842d <+16>: call 0x80482c0 <puts@plt>
0x08048432 <+21>: mov eax,0x0 …Run Code Online (Sandbox Code Playgroud) 我已经在Ubuntu上完成了Qt的安装?但是当我想启动Qt Creator时,出现如下错误:
/home/jackho/anaconda3/bin/python: symbol lookup error: /home/jackho/anaconda3/lib/python3.6/site-packages/PyQt5/Qt/plugins/platforms/../../lib/libQt5XcbQpa.so.5: undefined symbol: FT_Get_Font_Format
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我已经多次安装了Qt和PyQt5,但是没有用。
在以下代码段中,A由于复制省略,没有移动和复制
struct A;
A function1();
A function2();
int main(int argc, char**) {
if (argc > 3) {
A a = function1();
} else {
A a = function2();
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这很好,但是a在 if 块之外无法访问。当在a外面宣布时,然后移动发生
struct A;
A function1();
A function2();
int main(int argc, char**) {
A a;
if (argc > 3) {
a = function1();
} else {
a = function2();
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当它应该在调用站点的 if 块中发生到 if 范围之外的变量时,从复制省略中获利的推荐方法是什么?
考虑一段C++代码:
int main()
{
volatile int a=0;
if(!a)
++a;
}
Run Code Online (Sandbox Code Playgroud)
我使用g ++(Ubuntu 4.8.1-2ubuntu1~12.04)使用命令在amd64系统上编译它,g++ test.cpp -S -o test.S -masm=intel并获得以下代码:
...
mov eax, DWORD PTR [ebp-4]
test eax, eax
sete al
test al, al
je .L2
mov eax, DWORD PTR [ebp-4] ; don't use result of sete
add eax, 1
mov DWORD PTR [ebp-4], eax
.L2:
mov eax, 0 ; also drop result of sete
...
Run Code Online (Sandbox Code Playgroud)
这段代码真让我感到惊讶.起初我认为它与64位模式有关.但是当我尝试编译时-m32,这个位保持不变.
为什么它检查eax的是零,然后设置后重新检查结果再一次al给ZF?为什么不test eax,eax\n jne .L2 …
I'm trying to generate a header with a custom command. The header should be updated on each rebuild, so that the source file which includes it would also be rebuilt. (Actual command is a script, but here is a simplified version.)
Here's my project:
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
set(test_SOURCES test.c)
include_directories("${CMAKE_BINARY_DIR}")
set(VERSION_H_PATH "${CMAKE_BINARY_DIR}/version.h")
message("VERSION_H_PATH: ${VERSION_H_PATH}")
add_custom_command(OUTPUT "${VERSION_H_PATH}" COMMAND "touch" "${VERSION_H_PATH}")
#add_custom_target(GENERATE COMMAND "touch" "${VERSION_H_PATH}")
add_executable(myprog ${test_SOURCES})
add_dependencies(myprog GENERATE)
Run Code Online (Sandbox Code Playgroud)
test.c
#include <version.h>
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Now the problem is …
我试图将一些调试输出添加到C++ 03项目中并得到一些奇怪的结果.这是简化的测试代码:
#include <fstream>
int main()
{
{
std::ofstream file("/tmp/test.txt");
file << "hello" << " ... OK, this works\n";
}
std::ofstream("/tmp/test.txt",std::ios_base::app) << "hello"
<< " ... no, I mean hello!\n";
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,这是我在编译后得到的:
$ g++ test.cpp -o test && ./test && cat /tmp/test.txt
hello ... OK, this works
0x80487fe ... no, I mean hello!
Run Code Online (Sandbox Code Playgroud)
为什么在将字符串输出到未命名std::ofstream对象的情况下会得到十六进制数?为什么第二个字符串的后续输出有效?