小编Dov*_*eld的帖子

为什么std :: string没有提供到const char*的转换?

这更像是一个政策或历史问题.为什么决定为std :: string提供const char*转换?有人害怕有人可能会做printf("%s",s)并相信它会自动转换吗?关于这个问题有没有公开讨论?

c++ string implicit-conversion

13
推荐指数
3
解决办法
3125
查看次数

如何在emacs中指定后备字体?

我刚刚从源代码安装了Emacs 24,并希望安装主要字体和后备字体,当主要字体不包含我需要的国际字形时.在Linux下,这是由大多数环境通过fontconfig完成的,但是尝试设置字体

(set-default-font "Monospace 11")
Run Code Online (Sandbox Code Playgroud)

不起作用,而不是fontconfig Monospace集合,似乎我得到"Sans".

要获得等宽字体,我需要做类似的事情:

(set-default-font "Dejavu Sans Mono 11")
Run Code Online (Sandbox Code Playgroud)

但不幸的是它不包含我想要的字形.所以我的问题是,如果emacs提供了一种"后备"机制,只要主字体没有cona,它就会使用它

emacs

13
推荐指数
1
解决办法
2818
查看次数

如何使用可选参数创建交互式elisp函数

你如何编写一个elisp函数,它应该绑定到按键,默认情况下没有提示,但是在Ctrl-u之前提示用户输入参数.类似的东西(这是错误的语法,但我希望你能得到这个想法)?

 (defun my-message (&optional (print-message "foo"))
   (interactive "P")
   (message print-message))
 (global-set-key "\C-c\C-m" 'my-message)
Run Code Online (Sandbox Code Playgroud)

elisp

11
推荐指数
2
解决办法
3490
查看次数

如何在emacs中撤消call-last-kbd-macro

在emacs中,我有时会错误地调用call-last-kbd-macro.在撤消时我会预期撤销以原子方式撤消键盘宏的整个效果,但这不会发生.相反,我发现自己必须一次撤消宏的每一步.如何在执行宏之前让emacs返回缓冲区状态?

emacs undo

7
推荐指数
1
解决办法
530
查看次数

在 pybind11 中引用 C++ 分配的对象

我正在尝试使用 pybind11 创建一个 python 绑定,该绑定引用一个 C++ 实例,该实例的内存在 C++ 端处理。这是一些示例代码:

import <pybind11/pybind11>

struct Dog {
    void bark() { printf("Bark!\n"); }
};

int main()
{
  auto dog = new Dog;
  Py_Initialize();
  initexample(); // Initialize the example python module for import 

  // TBD - Add binding  between dog and example.dog .

  PyRun_StringFlags("import example\n"
                    "\n"
                    "example.dog.bark()\n"  // Access the C++ allocated object dog.
                    , Py_file_input, main_dict, main_dict, NULL);
  Py_Finalize();
}
Run Code Online (Sandbox Code Playgroud)

example.dog我一直困惑于如何创建 python和 C++变量之间的链接dog

我不能使用py:class_<Dog>.def(py::init<>()),因为这将分配一个新的实例Dog,这不是我想要的。

c++ python pybind11

6
推荐指数
2
解决办法
5627
查看次数

如何将 python c-extension 方法声明为类方法?

我正在为一个 C++ 类编写一个 python 包装器,它为替代的“构造函数”提供了几种静态方法。我想知道如何通过 python c-api 导出这些?

这是相关 C++ 代码的存根。

 PyObject *PyFoo_FromFoo(Foo foo);

 // This should be a class method that create a new instance of PyFoo().
 PyObject *
 PyFoo_Gen1(PyObject *self, PyObject *args)
 {
     Foo foo;  // Init this according to args

     return PyFoo_FromFoo(foo);
 }

 static PyMethodDef PyFoo_methods[] = {
    {"Gen1", (PyCFunction)PyFoo_Gen1, METH_VARARGS, "Gen1 foo creator" },
    {NULL}  /* Sentinel */
 };

 PyTypeObject PyFooType = {
   :
   PyFoo_methods, /* tp_methods */
   :
 }

 PyObject *PyFoo_FromFoo(Foo foo)
 {
    PyFoo *v …
Run Code Online (Sandbox Code Playgroud)

python python-c-api

5
推荐指数
1
解决办法
1432
查看次数

如何将 gdb stacktrace 与运行时生成的机器代码一起使用?

我继承了一些聪明的 GNU/Linux x64 机器代码,它围绕 c 函数调用创建了机器代码包装器。我猜想,用高级语言术语来说,代码可能被称为装饰器或闭包。该代码运行良好,但不幸的是,当调用包装器时,它会吞噬 gdb 中的堆栈跟踪。

\n\n

根据我从网上了解到的信息,gdb 使用https://en.wikipedia.org/wiki/DWARF作为分离堆栈中堆栈帧的指南。这对于静态代码来说效果很好,但显然运行时生成和调用的代码没有在 DWARF 框架中注册。

\n\n

我的问题是,在这种情况下是否有任何方法可以挽救堆栈跟踪?

\n\n

这是一些显示问题的类似 C 代码。

\n\n
typedef int (*ftype)(int x);\nint wuz(int x) { return x + 7; }\nint wbar(int x) { return wuz(x)+5; }\nint main(int argc, char **argv)\n{\n  const unsigned char wbarcode[] = {\n    0x55 ,                            //  push   %rbp\n    0x48,0x89,0xe5 ,                  //  mov    %rsp,%rbp\n    0x48,0x83,0xec,0x08 ,             //  sub    $0x8,%rsp\n    0x89,0x7d,0xfc ,                  //  mov    %edi,-0x4(%rbp)\n    0x8b,0x45,0xfc ,                  //  mov    -0x4(%rbp),%eax\n    0x89,0xc7 ,                       //  mov    %eax,%edi\n …
Run Code Online (Sandbox Code Playgroud)

c gdb x86-64

5
推荐指数
1
解决办法
528
查看次数

如果持续时间太大,为什么 std::condition_variable::wait_for() 返回超时?

在 g++ 11.2.1 下出现以下行为。std::condition_variable wait_for如果超时变量太大,该方法立即返回。特别是在下面的程序中,如果num_years==1,则程序将按预期挂起等待(大概等待 1 年),但如果该变量num_years==1000,则程序立即返回。

为什么会出现这种情况?这是 g++ 中的错误吗?还有一个相关的问题,如何cv.wait_for()无限期地等待,而不是猜测一个大的超时值?

//  This is 'cv_wait.cc' compile with:
//  
//    g++ -o cv_wait -std=c++2a cv_wait.cc
//
// An example showing that wait_for() returns immediately with a timeout
// return value if the duration variable is "too large".
//

#include <iostream>
#include <condition_variable>
#include <chrono>

int main(int argc, char **argv)
{
  std::condition_variable cv;
  std::mutex cv_m;

  // If num_years is "too large", e.g. 1000, then cv.wait_for() …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

4
推荐指数
1
解决办法
729
查看次数

如何在 git merge 提交中列出冲突的文件(父级都有更改的文件)?

qgit 有一个很好的选择,可以在合并提交中查看“有趣”的文件,其中有趣的文件被定义为在两个父文件中都有更改的文件。查看此类文件的相应命令行是什么?

git

3
推荐指数
1
解决办法
281
查看次数

如何使用交叉编译器i686-w64-mingw32-gcc指定win32或Windows 64目标

我最近在Fedora Linux下下载了mingw-w64软件包,以便能够交叉编译目标win32和"Windows 64".但我不明白如何指定我想要使用的目标.我需要向gcc和链接器提供哪些标志才能选择我的目标体系结构?

gcc fedora cross-compiling

3
推荐指数
1
解决办法
3822
查看次数