小编mus*_*tze的帖子

Vim折叠 - 标记打开折叠

有没有办法看到,在当前文件中打开折叠的位置?我个人在打开折叠和四处走动时遇到问题,我无法找到折叠开始的线!也许有一个选项可以在数字旁边设置漂亮的折叠提示.也许是这样的:

+ 1 void myfunc(void) {
| 2     printf("Hello World\n");
| 3     printf("Goodby World!\n");
- 4 }
  5
  6 void anotherfunc(void)
...
Run Code Online (Sandbox Code Playgroud)

这将是非常好的!我已经使用谷歌并使用了vim-help但是没有办法做到这一点.

亲切的问候,musicmatze

vim folding

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

有没有一种方法可以获取电池信息(状态,插入状态等)而无需在Linux上读取proc / sys文件?

我想获取有关Linux上C语言中电池的信息。我想要阅读或解析任何文件!是否有用于acpi /内核或任何其他模块的低级接口来获取我想要的信息?

我已经在网上搜索了,但是每个问题都会得到答案“ parse / proc / foo / bar”。我真的不想这样做,因为我认为低级接口的更改不会像File那样快。

最好的祝福。

c linux battery kernel acpi

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

如何在nixos中覆盖单个程序包的编译标志?

CFLAGS在NixOS / Nix环境中,如何为单个软件包覆盖编译标志(如中所示)?

这是我现在所拥有的:

let
   optimizeForThisHost = pkg:
     pkgs.lib.overrideDerivation pkg (old: {
       exportOptimizations = ''
         export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -fPIC -O3 -march=native"
       '';
       phaseNames = ["exportOptimizations"] ++ old.phaseNames;
     });
in
muttWithoutThings = pkgs: (pkgs.mutt.override {
    sslSupport  = false;
    saslSupport = false;
    imapSupport = false;
    withSidebar = false;
 };
});

mutt = pkgs:
    (optimizeForThisHost (muttWithoutThings pkgs));
Run Code Online (Sandbox Code Playgroud)

在我configuration.nix,虽然这失败了

error: attribute ‘phaseNames’ missing
Run Code Online (Sandbox Code Playgroud)

package compiler-optimization nixos nix cflags

5
推荐指数
2
解决办法
1134
查看次数

我可以获得指向当前函数的指针吗?

是否有可能获得指向当前函数的指针?如果是,我该怎么办?

动机:我有一个功能做一些日志记录,并想打电话

log(currentfunc, "blabla")
Run Code Online (Sandbox Code Playgroud)

例如,哪些输出.

c logging pointers function

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

如何使用 git 查找已删除的行?

有时,我想重新添加一些我前段时间从存储库中删除的代码。我总是使用诸如tig浏览历史记录之类的工具来查找删除了某些行的提交。

有没有办法用 git 找到删除的行?类似于git-grep但对于提交内容而不是提交消息?

git version-control

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

分配差异

可能重复:
声明和malloc之间的区别

这两个程序有区别吗?

int main(void) {
    char str[80];
}
Run Code Online (Sandbox Code Playgroud)

int main(void) {
    char * str = (char*) malloc( sizeof(char) * 80 );
}
Run Code Online (Sandbox Code Playgroud)

那么使用malloc和类似数组的语法之间有区别吗?所以如果我需要80个字符的内存,我应该使用malloc而不是其他可能性,对吧?

我会试着回答我自己的问题!

c arrays malloc pointers

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

从markdown文件中删除YAML标头

如何从Ruby中的文本文件中删除像这样的YAML标头:

---
date: 2013-02-02 11:22:33
title: "Some Title"
Foo: Bar
...

---
Run Code Online (Sandbox Code Playgroud)

(YAML被三个破折号( - )包围)

我试过了

text.gsub(/---(.*)---/, '') # text is the variable which contains the full text of the file
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

ruby regex yaml replace

3
推荐指数
2
解决办法
1535
查看次数

C块内部有什么功能?

我在C函数的定义中发现了一个奇怪的块使用(在动态窗口管理器的源代码中).

它是函数定义中的一个块.该文件的第944行有一个例子.这是关于什么的?

void
grabbuttons(Client *c, Bool focused) {
  updatenumlockmask();
  {
    unsigned int i, j;
    unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
    //some more code
  }
}
Run Code Online (Sandbox Code Playgroud)

c scope function

2
推荐指数
1
解决办法
835
查看次数

为什么我不能有 std::optional<T> 其中 T 是抽象的?

这不起作用:

struct Type {
    virtual bool func(const std::string& val) const noexcept = 0;
}

// in main
optional<Type> = some_function_returning_optional_type();
Run Code Online (Sandbox Code Playgroud)

并失败并显示错误消息:

error: cannot declare field 'std::experimental::fundamentals_v1::_Optional_base<Type, false>::<anonymous union>::_M_payload' to be of abstract type 'Type'
Run Code Online (Sandbox Code Playgroud)

将 更改Type为具有非纯函数有效,但在这种情况下不合适,因为Type在我的代码中不能有 的实例,只有从它继承的类才能存在。

c++ virtual templates abstract optional

2
推荐指数
1
解决办法
986
查看次数

在C中,是否保证1/2 == 0?

它在C中得到保证1/2 == 0吗?我需要它来实现二进制搜索:

/*
 * len is the array length
 * ary is an array of ptrs
 * f is a compare function
 * found is a ptr to the found element in the array
 * both i and offset are unsigned integers, used as indexes
 */

for(i = len/2; !found && i < len; i += offset) {
    res = f(c->ary[i]);

    if (res == 0) {
        found = c->ary[i];
    }
    else {
        offset = (res < 0 …
Run Code Online (Sandbox Code Playgroud)

c arrays math integer binary-search

0
推荐指数
1
解决办法
517
查看次数