假设我有一个示例源文件test.c,我正在编译它:
$ gcc -03 -Wall
test.c看起来像这样..
/// CMP128(x, y)
//
// arguments
// x - any pointer to an 128-bit int
// y - any pointer to an 128-bit int
//
// returns -1, 0, or 1 if x is less than, equal to, or greater than y
//
#define CMP128(x, y) // magic goes here
// example usages
uint8_t A[16];
uint16_t B[8];
uint32_t C[4];
uint64_t D[2];
struct in6_addr E;
uint8_t* F;
// use CMP128 on any combination of pointers …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何访问链接器在运行时生成的构建 ID。
从该页面,https://linux.die.net/man/1/ld
当我构建一个测试程序时,例如:
% gcc test.c -o test -Wl,--build-id=sha1
Run Code Online (Sandbox Code Playgroud)
我可以看到二进制文件中存在构建 ID:
% readelf -n test
Displaying notes found in: .note.gnu.build-id
Owner Data size Description
GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring)
Build ID: 85aa97bd52ddc4dc2a704949c2545a3a9c69c6db
Run Code Online (Sandbox Code Playgroud)
我想在运行时打印它。
编辑:假设您无法访问加载正在运行的进程的 elf 文件(权限、嵌入式/无文件系统等)。
编辑:接受的答案有效,但链接器不一定必须将变量放在该部分的末尾。如果有一种方法可以获取指向该部分开头的指针,那就更可靠了。
我正在寻找一个将errno整数转换为其名称的API。
例如:
int fd;
if((fd = open(path, O_RDONLY)) == -1)
printf("error: %d %s %s\n", errno, strerror(errno), ERRNONAME(errno));
Run Code Online (Sandbox Code Playgroud)
所以,ERRNONAME将产生一个名称,如"EINVAL","EPERM"等这可能吗?
我想找到列78(行上第78个字符)不是空格的所有行.
理想情况下,我想像普通搜索一样使用它.
我对perl有一个想法,我正在试图找出实现它的最佳方法.
我们的想法是让每个运算符的新版本将未定义的值视为该操作的标识.例如:
$a = undef + 5; # undef treated as 0, so $a = 5
$a = undef . "foo"; # undef treated as '', so $a = foo
$a = undef && 1; # undef treated as false, $a = true
Run Code Online (Sandbox Code Playgroud)
等等.
理想情况下,这将是语言作为一个pragma,或其他东西.
use operators::awesome;
Run Code Online (Sandbox Code Playgroud)
但是,如果我能够自己实现这个特殊的逻辑,然后在需要的地方调用它,我会感到满意:
use My::Operators;
Run Code Online (Sandbox Code Playgroud)
问题是,如果我说My :: Operators中的"use overload"只会影响被祝福到My :: Operators中的对象.
所以问题是:是否有一种方法(使用"overoad"或其他方式)来执行"通用运算符重载" - 这将被调用所有操作,而不仅仅是对受祝福标量的操作.
如果不是 - 谁认为这将是个好主意!这将节省我这种代码的TON
if($object && $object{value} && $object{value} == 15)
replace with
if($object{value} == 15) ## the special "is-equal-to" operator
Run Code Online (Sandbox Code Playgroud)