左旋异构

Something interesting

在编译gRPC的过程中发现编译到最后弹出如下错误提示:

1
2
3
4
5
6
[PROTOC]  Generating protobuf CC file from src/proto/grpc/channelz/channelz.proto
[GRPC] Generating gRPC's protobuf service CC file from src/proto/grpc/channelz/channelz.proto
/home/work/tools/grpc_1.11/bins/opt/grpc_cpp_plugin: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /home/work/tools/grpc_1.11/bins/opt/grpc_cpp_plugin)
/home/work/tools/grpc_1.11/bins/opt/grpc_cpp_plugin: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /home/work/tools/grpc_1.11/bins/opt/grpc_cpp_plugin)
--grpc_out: protoc-gen-grpc: Plugin failed with status code 1.
make: *** [/home/work/tools/grpc_1.11/gens/src/proto/grpc/channelz/channelz.grpc.pb.cc] Error 1
阅读全文 »

查看文件大小

1
stat filepath
1
wc -c filepath
1
ls -s filepath

轮子哥的解释:

顶层和底层的翻译很容易让人误解为就只有两层,实际上当然是不是的。首先我们假设有这样的代码:template using Const = const T;
template using Ptr = T*;
然后const int *** const shit = nullptr;
要怎么看呢?很简单,不要用const和*,用Const和Ptr来表达,马上明白:Const<Ptr<Ptr<Ptr<Const>>>> shit = nullptr;
一秒学会

阅读全文 »

一个实验

  • 使用join
    在join位置阻塞主线程
  • 使用detach
    不阻塞主线程(即使线程没执行完,一旦主线程结束则该线程亦结束)
阅读全文 »

定义与声明的区别

声明(Declaration)使得名字为程序所知,一个程序想使用在别处出现的名字就需要声明。
定义(Definition)产生与名字相关的实体,分配内存空间。

阅读全文 »

今天看到代码里有一段这样的操作:

1
2
3
4
5
6
7
8
int getline(std::string &str, FILE *fp) {
char *buf = reinterpret_cast<char *>(malloc(2048));
//something
str = buf;

free(buf);
buf = NULL;
return str.length();

第一反应是这句str = buf不是把buf的指针赋给str,然后free不是啥都没了吗?后来仔细看了看,其实std::string的赋值操作符是重载的,有一个定义是:

1
string& operator= (const char* s);

buf是直接把内容赋给了str,和指针无关了。

常用CMakeLists.txt里有几行

1
2
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -Wall -ggdb -g2")
阅读全文 »
0%