小编Ore*_*lom的帖子

全局变量位于elf文件中的哪个位置

我想学习elf文件,但是当我想到全局变量,全局静态变量和范围静态变量时,我有些困惑.例如:

int a = 2;
int b;

static int c = 4;
static int d;

void fun(){
  static int e = 6;
  static int f;
}


int main(void){
   fun();
}
Run Code Online (Sandbox Code Playgroud)

谁能告诉每个变量属于哪个细分?在我看来, b,df属于.bss段和a,c以及e属于数据段,但我不知道全局静态变量和ELF文件的全局变量之间的差异.

c linux elf

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

Graphviz 点垂直对齐节点

我有以下 graphviz 点输入文件:

digraph structs {
rankdir = LR;
node [shape=record];
hashTable [label="<f0>0|<f1>1|<f2>2|<f3>3|<f4>4|<f5>5|<f6>6|<f7>7|<f8>8"];
node_1_0 [label="<f0> one|<f1> two |<f2> three"];
node_1_1 [label="<f0> un |<f1> deux|<f2> trois"];
struct3 [label="<f0> einz|<f1> swei|<f2> drei"];
hashTable:f1 -> node_1_0:f0;
node_1_0:f2  -> node_1_1:f0;
hashTable:f4 -> struct3:f0;
}
Run Code Online (Sandbox Code Playgroud)

渲染如下:

在此输入图像描述

如何让[one|two|third]节点与[un|deux|trois]节点垂直对齐?谢谢!

dot graphviz

8
推荐指数
1
解决办法
1万
查看次数

Markdown 图像标题

我有一个包含图像的简单 Markdown 文件:

![image](MyLovelyImage.png "some title")
Run Code Online (Sandbox Code Playgroud)

我正在使用 GitHub 查看器,在那里我可以看到图像,但没有标题/说明文字。有什么办法可以解决这个问题吗?

markdown image

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

在C++ 17中迭代它时,从std :: set中删除一个元素

我已经读过这篇SO帖子了,这个也是关于std::set迭代过程中元素的擦除.但是,似乎C++ 17中存在一个更简单的解决方案:

#include <set>
#include <iostream>
int main(int argc,char **argv)
{
    std::set<int> s;

    s.insert(4);
    s.insert(300);
    s.insert(25);
    s.insert(-8);

    for (auto it:s)
    {
        if (it == -8)
        {
            s.erase(it);
        }
    }
    std::cout << "s = {";
    for (auto it:s)
    {
        std::cout << it << " ";
    }
    std::cout << "}\n";
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我编译并运行它时,一切都很完美:

$ g++ -o main main.cpp
$ ./main
s = {4 25 300 }
Run Code Online (Sandbox Code Playgroud)

擦除这样的元素有什么警告吗?谢谢.

c++ erase stdset c++17

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

在保留评论的同时提取Coq到Haskell

无论如何,在将Coq提取到Haskell时是否要保留评论?理想情况下,我希望机器生成的Haskell文件不受人类的影响,因此提取注释的动机很明显。但是,我找不到该怎么做的,我想知道这是否完全可能(?)。这是一个示例Coq文件:

(*************)
(* factorial *)
(*************)
Fixpoint factorial (n : nat) : nat :=
  match n with
  | 0 => 1
  | 1 => 1 (* this case is redundant *)
  | S n' => (mult n (factorial n'))
  end.

Compute (factorial 7).

(********************************)
(* Extraction Language: Haskell *)
(********************************)
Extraction Language Haskell.

(***************************)
(* Extract to Haskell file *)
(***************************)
Extraction "/home/oren/Downloads/RPRP/output.hs" factorial. 
Run Code Online (Sandbox Code Playgroud)

当我将其提取到Haskell时,除了析因内的注释丢失之外,其他所有功能都正常运行:

$ coqc ./input.v > /dev/null
$ cat ./output.hs
module Output where

import qualified Prelude …
Run Code Online (Sandbox Code Playgroud)

haskell comments coq

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

证明在Coq提取中的作用

我试图了解证明在Coq提取中的作用。我被两个取自有地板整数除法下面的例子在这里。我第一次尝试使用Admitted关键字:

(*********************)
(* div_2_even_number *)
(*********************)
Definition div_2_even_number: forall n,
  (Nat.Even n) -> {p:nat | n=p+p}.
Proof.
Admitted.

(*************)
(* test_even *)
(*************)
Definition test_even: forall n,
  {Nat.Even n}+{Nat.Even (pred n)}.
Proof.
Admitted.

(********************)
(* div_2_any_number *)
(********************)
Definition div_2_any_number (n:nat):
  {p:nat | n = p+p}+{p:nat | (pred n) = p+p} :=
  match (test_even n) with
  | left h => inl _ (div_2_even_number n h)
  | right h' => inr _ (div_2_even_number (pred n) h')
  end. …
Run Code Online (Sandbox Code Playgroud)

haskell coq coq-extraction

7
推荐指数
2
解决办法
139
查看次数

gradle 依赖 (c) 和 (n) 是什么意思?

非常接近这个SO帖子,并在评论中询问,但不清楚。

$ git clone https://github.com/k9mail/k-9.git
$ cd k-9/mail/protocols/smtp
$ ../../../gradlew dependencies | grep "4.7.1 (\*)\|4.7.1 (c)\|4.7.1 (n)" | sort -u
+--- com.jakewharton.timber:timber:4.7.1 (*)
+--- com.jakewharton.timber:timber:4.7.1 (n)
+--- com.jakewharton.timber:timber:{strictly 4.7.1} -> 4.7.1 (c)
Run Code Online (Sandbox Code Playgroud)

(c)和后缀是什么(n)意思?

gradle gradlew gradle-dependencies

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

询问 Union[...] 类型的 isinstance

我正在尝试询问isinstance有关用户定义类型的问题ConstData = Union[int, str]::

from typing import Union, Optional
ConstData = Union[int, str]
def foo(x) -> Optional[ConstData]:
    if isinstance(x, ConstData):  # <--- this doesn't work
    # if isinstance(x, (int, str)): <--- this DOES work ...
        return x
    return None
Run Code Online (Sandbox Code Playgroud)

不幸的是,它不起作用:

$ mypy main.py
main.py:4: error: Parameterized generics cannot be used with class or instance checks
main.py:4: error: Argument 2 to "isinstance" has incompatible type "object"; expected "Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]"
Found 2 errors in 1 …
Run Code Online (Sandbox Code Playgroud)

python types mypy

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

在Python数据类中创建唯一的ID

我的 python 数据类需要一个唯一的(无符号整数)id。这与so post非常相似,但没有明确的演员。

import attr
from attrs import field
from itertools import count
@attr.s(auto_attribs=True)
class Person:
    #: each Person has a unique id
    _counter: count[int] = field(init=False, default=count())
    _unique_id: int = field(init=False)

    @_unique_id.default
    def _initialize_unique_id(self) -> int:
        return next(self._counter)
Run Code Online (Sandbox Code Playgroud)

还有更多“pythonic”解决方案吗?

python attributes attr

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

Coq 中自然数后继的内射性

我有点困惑在自然数上定义的后继函数的单射性是否Coq是一个公理?根据维基百科/皮亚诺公理,它是一个公理(7)。当我查看Coq.Init.Peano手册页时,我看到以下内容:

定义 eq_add_S nm (H: S n = S m): n = m := f_equal pred H。

提示立即 eq_add_S: core.

它看起来像一个公理(?),但令我困惑的是,在该页面的顶部它说:

它陈述了有关自然数的各种引理和定理,包括皮亚诺算术公理(在 Coq 中,这些是可证明的)

这句话是不是有点歧义?

coq peano-numbers

6
推荐指数
1
解决办法
794
查看次数