-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpod_init.cpp
More file actions
51 lines (46 loc) · 1.55 KB
/
pod_init.cpp
File metadata and controls
51 lines (46 loc) · 1.55 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdint.h>
#include <string.h>
#include <iostream>
using namespace std;
// POD(Plain Old Data)结构体和C语言中的结构体兼容,能够正常使用memcpy memset
// bzero等函数,如下所示Options就是一个POD
// 对POD类/结构体,我们可以在构造函数中使用bzero或这bzero初始化内存
struct Options {
Options() {
// bzero(this, sizeof(*this));//not windows
memset(this, 0, sizeof(*this));
}
uint16_t tcpport;
uint16_t udpport;
uint16_t gperfport;
int threads;
};
int main(int argc, char const *argv[]) {
Options options;
// memset(&options, 0, sizeof(options));
// memset这一步可以省去,可以让我们在使用对象的时候更便捷
std::cout << "options.tcpport:" << options.tcpport << std::endl;
std::cout << "options.udpport:" << options.udpport << std::endl;
std::cout << "options.gperfport:" << options.gperfport << std::endl;
std::cout << "options.threads:" << options.threads << std::endl;
Options *op = new Options();
std::cout << "op->tcpport:" << op->tcpport << std::endl;
std::cout << "op->udpport:" << op->udpport << std::endl;
std::cout << "op->gperfport:" << op->gperfport << std::endl;
std::cout << "op->threads:" << op->threads << std::endl;
return 0;
}
// 测试
/*
[root@localhost common]# g++ pod_init.cpp -o pod_init
[root@localhost common]# ./pod_init
options.tcpport:0
options.udpport:0
options.gperfport:0
options.threads:0
op->tcpport:0
op->udpport:0
op->gperfport:0
op->threads:0
*/
// Options from muduo