info registers在gdb中运行时,我们得到类似于以下内容的输出:
rax 0x1c 28
rbx 0x0 0
rcx 0x400a60 4196960
rdx 0x7fffffffde88 140737488346760
rsi 0x1 1
rdi 0x400932 4196658
rbp 0x0 0x0
rsp 0x7fffffffde68 0x7fffffffde68
r8 0x400ad0 4197072
r9 0x7ffff7dea560 140737351951712
r10 0x7fffffffdc30 140737488346160
r11 0x7ffff7732dd0 140737344908752
r12 0x4007f0 4196336
r13 0x7fffffffde80 140737488346752
r14 0x0 0
r15 0x0 0
rip 0x7ffff7732dd0 0x7ffff7732dd0
eflags 0x202 [ IF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
Run Code Online (Sandbox Code Playgroud)
虽然我明白了rax, …
我是Python C-API和模块创建的新手.我试图创建一个c-hash python模块.我使用python 3.4.3和TDM-gcc(64bit)4.9.2进行Windows上的编译.
这是我的代码:
// hash_mod.c
#include <Python.h>
unsigned long _hash(unsigned char const* str)
{
unsigned long hash = 5381;
int c;
int i;
i = 0;
while (str[i] != '\0')
{
c = str[i];
hash = ((hash << 5) + hash) + c;
++i;
}
return hash;
}
static PyObject*
hash_hash(PyObject* self, PyObject* args)
{
unsigned char const* str;
if (!PyArg_ParseTuple(args, "s", &str))
return NULL;
return PyLong_FromUnsignedLong(_hash(str));
}
static PyMethodDef HashMethods[] = {
{"hash", hash_hash, METH_VARARGS, "String Hash"}, …Run Code Online (Sandbox Code Playgroud) 鉴于磁带的第0个单元格中的数字已被填充,其余部分仅用作刮擦单元格(即它们都从0开始并且是临时的 - 我不在乎它们发生了什么),我想要更换第0个单元格为0或1. 0表示偶数,1表示奇数.
基本上,我想做的是(在C-esque伪代码中):
cell[0] = (cell[0] % 2)
Run Code Online (Sandbox Code Playgroud)
我知道有一个divmod算法定义如下:
如果不需要保留n,请使用以下变体:
Run Code Online (Sandbox Code Playgroud)# >n d [->-[>+>>]>[+[-<+>]>+>>]<<<<<] # >0 d-n%d n%d n/d
但是,因为X % 2 == X & 1,即X mod 2是X的最右边,我认为divmod在计算的复杂性方面可能过度.
是否有更好的算法/技术来确定细胞是否均匀?
我在codegolf.stackexchange上找到以下代码来打印ASCII字符的代码表:
#include <stdio.h>
int main(){
char i;
for(i = 0; i < 256; i++){
printf("%3d 0x%2x: %c\n", i, i, i);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
由于chars中存储了单个字节,因此它们始终存在< 256且循环永远不会终止.我想在编译时发现这一点.
很好,clang给出以下警告:
a.c:5:18: warning: comparison of constant 256 with expression of type 'char' is always true [-Wtautological-constant-out-of-range-compare]
for(i = 0; i < 256; i++){
~ ^ ~~~
Run Code Online (Sandbox Code Playgroud)
但是,既没有gcc也没有gcc -Wall任何形式的警告.是否有任何一组命令行选项可以打开这种警告?或者在gcc中不可能吗?
当你尝试echo一堆反斜杠时,Zsh似乎做了一些奇怪的反斜杠.我似乎无法找到一个非常明确的模式.这种疯狂的原因是什么?当然,如果我真的想要正确使用反斜杠,那么我会使用正确的引用等,但为什么会发生这种情况呢?
这是一个显示相同的小例子:
$ echo \\
\
$ echo \\ \\
\ \
$ echo \\ \\ \\
\ \ \
$ echo \\ \\ \\ \\
\ \ \ \
$ echo \\\\ \\ \\
\ \ \
$ echo \\\\\\ \\
\\ \
$ echo \\\\\\\\
\\
Run Code Online (Sandbox Code Playgroud)
我最初在不久前独立发现了这个,但Zach Riggle的这条推文提醒了它.
c ×3
algorithm ×1
backslash ×1
brainfuck ×1
disassembly ×1
gcc ×1
gcc-warning ×1
gdb ×1
python-3.x ×1
x86 ×1
zsh ×1