C++ 重复引用符号 问题 Inline keyword

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// h.hpp
#ifndef _H_HPP
#define _H_HPP

void h()
{
...
}

#endif

-----------------------------------------------------

// a.cpp

#include "h.hpp"

int main()
{
h();
return 0;
}

-----------------------------------------------------

// b.cpp

#include "h.hpp"

void b()
{
h();
}

执行下面的编译语句:

1
g++ a.cpp b.cpp -o main

通过inline 或者 static 来解决在编译过程中产生相同符合的问题。

使用static,最终会产生两个不同的函数符号

使用inline 被 include 进多个编译单元的 h 函数,在多个编译单元中分别编译,得到了多个副本;在链接的时候,链接器随便选取其中的一个副本保留,其余的被丢弃。

cargo,rust基础笔记0

cargo

1
2
3
4
5
cargo new "project_name"
cargo build
cargo run
cargo test
cargo build --release
  • std::rc reference counted
  • std::cell::RefCell
1
2
3
4
5
6
7
use std::rc::Rc;
let my_rc = Rc::new(());
Rc::downgrade(&my_rc);

let foo = Rc::new(vec![1.0,2.0,3.0]);
let a = foo.clone();
let b = Rc::clone(&foo);

Borrowing

1
2
3
4
5
6
7
8
9
10
11
fn foo(v1: &Vec<i32>, v2: &Vec<i32>) -> i32 {
// do stuff with v1 and v2

// return the answer
42
}

let v1 = vec![1, 2, 3];
let v2 = vec![1, 2, 3];

let answer = foo(&v1, &v2);

Rules about borrowing in Rust

  1. any borrow must last for a scope no greater than that of the owner
  2. you may have one or the other of these two kinds of borrows, but not both at the same time
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
enum Coin {
Penny,
Nickel,
Dime,
Quarter,
}
fn value_in_cents(coin: Coin) -> u8 {
match coin {
Coin::Penny => {
println!("Lucky penny!");
1
},
Coin::Nickel => 5,
Coin::Dime => 10,
Coin::Quarter => 25,
}
}
1
2
3
4
5
6
7
8
9
10
fn plus_one(x: Option<i32>) -> Option<i32> {
match x {
None => None,
Some(i) => Some(i + 1),
}
}

let five = Some(5);
let six = plus_one(five);
let none = plus_one(None);
if let 简单控制流
1
2
3
4
5
6
7
8
9
10
11
12
13
14
let some_u8_value = Some(0u8);
match some_u8_value {
Some(3) => println!("three"),
_ => (),
}
if let Some(3) = some_u8_value {
println!("three");
}
let mut count = 0;
if let Coin::Quarter(state) = coin {
println!("State quarter from {:?}!", state);
} else {
count += 1;
}

使用pub来使得mod、结构体、函数共有。

使用super来调用父模块的东西

1
2
3
4
5
6
7
8
9
10
fn serve_order() {}

mod back_of_house {
fn fix_incorrect_order() {
cook_order();
super::serve_order();
}

fn cook_order() {}
}
使用struct 来定义结构体成员变量,使用impl来定义结构方法
使用trait关键字定义一个接口
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
trait Area{
fn area(&self) -> f64;
}

struct Circle{
r : f64;
}
impl Area for Circle{
fn area(&self) -> f64{
(3.14 * self.r)
}
}
fn main(){
let r = Circle{r :10.5};
println!("area={:?}",r.area());
}

std::include

1
2
3
4
let my_string = include!("monkeys.in");
mod math{
include!("math.rs");
}

mod math;

泛型数据类型

git设置socks5代理

1
2
git config --global https.proxy 'socks5://127.0.0.1:2080'
git config --global http.proxy 'socks5://127.0.0.1:2080'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
set http_proxy=http://127.0.0.1:2080

set https_proxy=http://127.0.0.1:2080

set http_proxy_user=user
set http_proxy_pass=pass

set https_proxy_user=user
set https_proxy_pass=pass

# 恢复
set http_proxy=

set https_proxy=

# Ubuntu 下命令为 export
# export http_proxy=http://127.0.0.1:1080

个人台式机(工作站)的推荐配置

类型 型号 价格
CPU 酷睿i7-8700 649
主板 微星B360M 1764
CPU风扇 酷冷至尊T400i 65
GPU 影驰rtx-2070 Gamer 3499
内存 金斯顿骇客神条8Gb*4 968
固态硬盘 西部数据 Sn750 500Gb 533
机械硬盘 东芝 3TB P300 489
机箱 先马黑洞 295
电源 酷冷至尊650w 469
网线 绿联千兆 12
蓝牙 绿联电脑pc外接蓝牙 29
8772

配置完成,总体上还是比较满意的。

值得一提的是我是做图形计算、并行计算这块的,所以显卡的显存、效率都很重要,rtx-2070 Gamer在我程序的测试下 ,可以跟实验室的Titan Xp有差不多的性能;并且这块显卡在游戏和并行计算上效率特别高,不愧是图灵系列的一块卡。

西部数据这块固态,速度非常快,切换窗口,打开文件速度都非常明显,推荐购买。