## UE4:Clion debug project on MacOS

Executable选择为项目目录下的Binaries中编译出来的可执行文件，然后加上参数-game -log即可。

## UE:MODULE_NAME_API

UE中的模块，如果定义的符号允许被外部模块访问，则需要在class前加MODULE_NAME_API，这个宏是什么意思呢？

MacOS则是一个空的宏定义：

Windows的为__declspec

## UE:模块的宏定义

UE中模块的宏定义会汇总在这个文件下：

## MacOS安装UE

UE要求MacOS的分区格式为不区分大小写（不然EpicLauncher也无法安装），而且安装引擎的要求是系统版本大于10.13.5，否则会出现引擎崩溃和一些不支持的情况(尝试忽略错误无法安装成功)。

### 使用VSC编写代码(UE_4.18+)

You can now use Visual Studio Code to write code on all UE4 host platforms. To use it, select "Visual Studio Code" as your preferred IDE from the editor preferences dialog, or add the -vscode argument when generating project files on the command line. All platforms are also required to have the .NET Core 2.0 runtimes installed, which can be obtained from the Microsoft .NET Core website.
To use Visual Studio Code to build and debug all project types, some additional extensions are required. On all platforms, make sure the Microsoft C/C++ extension, and the C# extension are installed. On Linux and Mac, the "Mono Debug" extension is required to debug C# projects, and the “LLDB Debugger” extension is required to debug C++ projects. Also, in order to debug C# projects, the mono runtime must be installed:

• On OS X: brew install mono
• On Linux:sudo apt-get install mono-complete

## 解除MacOS安装软件的限制

• 允许任何来源，运行第三方应用
• 安装灰色的dmg

## UE4:SpawnSoundAtLocation失败的情况

UE中创建一个声音使用的是UGameplatStatic::SpawnSoundAtLocation，但是在项目中发现有时候它会被创建失败，看了一下代码，发现确实会存在创建失败的情况。

FAudioDevice::LocationIsAudible中做了检测：

ListenerUGameViewportClient::Draw中被设置：

Listener的位置是通过PlayerController::GetAudioListenerPosition来获取的，而该函数获取的是AudioListenerComponent的位置和旋转，可以通过PlayerController::SetAudioListenerOverride来设置使用的组件。

PS:只有在当前的AudioDeviceMainAudioDevice并且不在焦点的时候才不会更新Listener的位置。

## MBR无损迁移到GPT

1. 进入PE,使用GHOST备份当前MBR的C盘
2. 备份完成后，删除原C盘硬盘的所有分区，修改分区表为GPT并创建好分区
3. 在PE中使用GHOST将备份的系统还原到GPT的分区中
4. 引导原版的系统镜像(将boot/efi/bootmgrbootmgr.efi放入恢复完成的分区)
5. 重启进入原版镜像的安装模式，使用修复系统会重建EFI的系统引导，修复完成即可。

## 类内默认值与构造函数初始化的顺序

[IOS/IEC 14882:2014 §12.6.2.9]If a given non-static data member has both a brace-or-equal-initializer and a mem-initializer, the initialization specified by the mem-initializer is performed, and the non-static data member’s brace-or-equal-initializer is ignored.

the A(int) constructor will simply initialize i to the value of arg, and the side effects in i’s brace-or-equal-initializer will not take place.

## Windows窗口切换快捷键

Win+Shift+Left/Right：可以控制窗口在多个显示器上左移或者右移；
Win+Shift+Up：保持窗口宽度的同时最大化窗口；
Win+Shift+Down：最小化窗口；

PS:Win+Shift+S则是屏幕截图。

## UE4:GC Config of BaseEngine.ini

• AllowParallelGC：允许多线程执行GC
• TimeBetweenPurgingPendingKillObjects：GC的清理周期默认为60s，可以通过调用：

• CreateGCClusters：开启可以防止对很多子物体进行GC遍历。

## Linux添加PATH路径

Linux上可以通过export来查看当前的PATH路径列表：

1. 直接在终端中添加PATH，只在当前环境有效，退出终端失效：
1. 为当前用户添加PATH路径，打开~/.profile增加以下内容：

## 变量模板的特化

note: use -ftemplate-depth=N to increase recursive template instantiation depth

## What is the Object in C/C++?

[ISO/IEC 14882:2014 §1.8]An object is a region of storage. [ Note: A function is not an object, regardless of whether or not it occupies storage in the way that objects do.——end note ] An object is created by a definition (3.1), by a new-expression (5.3.4) or by the implementation (12.2) when needed.

[ISO/IEC 14882:2014 §1.8]An object can have a name (Clause 3). An object has a storage duration (3.7) which influences its lifetime (3.8). An object has a type (3.9). The term object type refers to the type with which the object is created.

C语言中的对象(object)概念与C++中类似，也是存储即对象

[ISO/IEC 9899:1999 §3.14]region of data storage in the execution environment, the contents of which can represent values

## C++模板必须提供声明和定义的原因

C++历史上(C++03)曾经允许过模板的分离编译(使用export)，但是这个特性在C++11之后就废除掉了，一是其局限性太大(并不像普通的提供声明-定义的分离式编译那样，编译时仍需要提供代码的实现)，二是其太难实现了(只有一个编译器Comeau实现过)。

## VS修改文件编码

File下添加Advanced Save Options选项：

PS:最好代码都使用Unicode编码，避免编码问题造成奇奇怪怪的编译错误。

## C++模板特化实例的static成员

[ISO/IEC 14882:2014 § 14.7]Each class template specialization instantiated from a template has its own copy of any static members.

## this不能用在函数默认参数的原因

[ISO/IEC 14882:2014 §8.3.6.9]A default argument is evaluated each time the function is called with no argument for the corresponding parameter. The order of evaluation of function arguments is unspeciﬁed. Consequently, parameters of a function shall not be used in a default argument, even if they are not evaluated. Parameters of a function declared before a default argument are in scope and can hide namespace and class member names.

## 龙书DX12勘误

5.设k为标量，向量$u=(u_x,u_y,u_z)$。求证$\left| \left| k \right| \right|\left| \left| u \right| \right|$.

## GNU扩展：struct初始化[first ... last]

GNU的扩展支持以下这样一种结构初始化的写法(Designated-Inits)：

## 信号量的竞态条件

[CSAPP,2E,12.5.2]当有多个线程在等待同一个信号量的时候，不能够预测V操作要重启哪个线程。

## static成员初始化可以访问private成员

C++的static成员初始化是可以访问类的私有成员的：

[ISO/IEC 14882:2014 §9.4.2]The static data member run_chain of class process is defined in global scope; the notation process ::run_chain specifies that the member run_chain is a member of class process and in the scope of class process. In the static data member definition, the initializer expression refers to the static data member running of class process. — end example ]

## CMD命令：拷贝文件夹

windows下拷贝多级目录可以使用xcopy.

## C语言中的枚举就是整型

[ISO/IEC 9899:1999 §6.4.4.4.2]An identifier declared as an enumeration constant has type int.

[ISO/IEC 9899:1999 §6.7.2.2.3]The identifiers in an enumerator list are declared as constants that have type int and may appear wherever such are permitted.

## C++中纯虚函数不能够提供定义

[ISO/IEC 14882:2014 §10.4]A function declaration cannot provide both a pure-specifier and a definition.

## C语言中聚合结构的初始化

C语言的聚合结构还有这种方式的初始化：

PS:sizeof(w) == ?是个有趣的问题。

## unspecified behavior

behavior, for a well-formed program construct and correct data, that depends on the implementation.[ Note: The implementation is not required to document which behavior occurs. The range of possible behaviors is usually delineated by this International Standard. — end note ]

## well-formed program

[ISO/IEC 14882:2014 §1.3.26]C++ program constructed according to the syntax rules, diagnosable semantic rules, and the One Definition
Rule (3.2).

## Implementation-Define(实现定义行为)

[ISO/IEC 14882:2014]behavior, for a well-formed program construct and correct data, that depends on the implementation and that each implementation documents

## UB(未定义行为)

[ISO/IEC 14882:2014 §1.9.4]This International Standard imposes no requirements on the behavior of programs that contain undefined behavior.
[ISO/IEC 14882:2014 §1.3.24]behavior for which this International Standard imposes no requirements [ Note: Undefined behavior may be expected when this International Standard omits any explicit definition of behavior or when a program uses an erroneous construct or erroneous data. Permissible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message). Many erroneous program constructs do not engender undefined behavior; they are required to be diagnosed. — end note ]

## 关于注入类名字(injected-class-name)的问题

[ISO/IEC 14882:2014(E) §9.0.2]The class-name is also inserted into the scope of the class itself; this is known as the injected-class-name. For purposes of access checking, the injected-class-name is treated as if it were a public member name.

[ISO/IEC 14882:2014(E) §11.1.5]In a derived class, the lookup of a base class name will find the injected-class-name instead of the name of the base class in the scope in which it was declared.

A) 公有继承的公有成员
B) 公有继承的私有成员
C) 公有继承的保护成员
D) 私有继承的公有成员

## reintrtpret_cast的转换(位模式的转换)

### 指针到整型的转换

reinterpret_cast不能用在转换任何类型的值到std::nullptr_t.

[ISO/IEC 14882:2014 §5.2.10.4]A pointer can be explicitly converted to any integral type large enough to hold it. The mapping function is implementation-defined. [ Note: It is intended to be unsurprising to those who know the addressing structure of the underlying machine. — end note ] A value of type std::nullptr_t can be converted to an integral type; the conversion has the same meaning and validity as a conversion of (void*)0 to the integral type. [ Note: A reinterpret_cast cannot be used to convert a value of any type to the type std::nullptr_t. — end note ]

### 整型到指针的转换

[ISO/IEC 14882:2014 §5.2.10.5]A value of integral type or enumeration type can be explicitly converted to a pointer. A pointer converted to an integer of sufficient size (if any such exists on the implementation) and back to the same pointer type will have its original value; mappings between pointers and integers are otherwise implementation-defined. [ Note: Except as described in 3.7.4.3, the result of such a conversion will not be a safely-derived pointer value. — end note ]

### 函数指针的转换

[ISO/IEC 14882:2014 §5.2.10.6]A function pointer can be explicitly converted to a function pointer of a diﬀerent type. The eﬀect of calling a function through a pointer to a function type (8.3.5) that is not the same as the type used in the definition of the function is undefined. Except that converting a prvalue of type “pointer to T1” to the type “pointer to T2” (where T1 and T2 are function types) and back to its original type yields the original pointer value, the result of such a pointer conversion is unspecified. [ Note: see also 4.10 for more details of pointer conversions. — end note ]

## tracert命令

Tracert 命令使用用 IP 生存时间 (TTL) 字段和 ICMP 错误消息来确定从一个主机到网络上其他主机的路由.

## offsetof不能用在非POD类型(Standard Layout)

offsetof是定义在stddef.h/cstddef中的一个宏，其作用是获取结构成员在结构上的偏移。

[ISO/IEC 14882:2014 §18.2.4]:The macro offsetof(type, member-designator) accepts a restricted set of type arguments in this International Standard. If type is not a standard-layout class (Clause 9), the results are undefined.The expression offsetof(type, member-designator) is never type-dependent (14.6.2.2) and it is value-dependent (14.6.2.3) if and only if type is dependent. The result of applying the offsetof macro to a field that is a static data member or a function member is undefined. No operation invoked by the offsetof macro shall throw an exception and noexcept(offsetof(type, member-designator)) shall be true.
Note that offsetof is required to work as specified even if unary operator& is overloaded for any of the types involved.

[ISO/IEC 14882:2014 §3.9.9]:Scalar types, standard-layout class types (Clause 9), arrays of such types and cv-qualified versions of these types (3.9.3) are collectively called standard-layout types.

Standard Layout Class则又是：
A standard-layout class is a class that:

• has no non-static data members of type non-standard-layout class (or array of such types) or reference,
• has no virtual functions (10.3) and no virtual base classes (10.1),
• has the same access control (Clause 11) for all non-static data members,
• has no non-standard-layout base classes,
• either has no non-static data members in the most derived class and at most one base class with non-static data members, or has no base classes with non-static data members, and
• has no base classes of the same type as the first non-static data member.

## C++中的Standard Layout types

[ISO/IEC 14882:2014 §3.9.9]:Scalar types, standard-layout class types (Clause 9), arrays of such types and cv-qualified versions of these types (3.9.3) are collectively called standard-layout types.

Standard Layout Class则又是：
A standard-layout class is a class that:

• has no non-static data members of type non-standard-layout class (or array of such types) or reference,
• has no virtual functions (10.3) and no virtual base classes (10.1),
• has the same access control (Clause 11) for all non-static data members,
• has no non-standard-layout base classes,
• either has no non-static data members in the most derived class and at most one base class with non-static data members, or has no base classes with non-static data members, and
• has no base classes of the same type as the first non-static data member.

## 禁用MIUI的更新提示

ROOT手机，安装RE文件管理器。

## 在基类子对象内对this指针做放置new操作

this的生命周期的终结时机为调用析构函数之后，调用析构函数则意味着该类内的所有数据均变成了无意义的存在，对无意义的东西做操作是UB行为。

## MinGW-W64编译32位程序

GCC支持-m32参数来将代码编译到32位程序。但是如果你的MinGW是SEH或者DWARF的异常模型，则他们是单一平台的，不支持编译到32位程序。
stackoverflow上有个回答：How do I compile and link a 32-bit Windows executable using mingw-w64

## C语言的隐式函数声明

[ISO/IEC 9899:1990 6.3.2.2] If the expression that precedes the parenthesized argument list in a function call consists solely of an identifier. and if no declaration is visible for this identifier, the identifier is implicitly declared exactly as if. in the innermost block containing the function call. the declaration

[ISO/IEC 9899:1999 Foreword] remove implicit function declaration

1. 编译器隐式声明了printf函数
2. 链接器默认链接了stdlib，所以才不会产生符号未定义的链接错误

• -nodefaultlibs: 不使用标准系统库，只有编译参数中指定的库才会传递给链接器
• -nostdlib: Do not use the standard system startup files or libraries when linking.
• -nolibc: Do not use the C library or system libraries tightly coupled with it when linking.

Guide to x86-64

## 增强扫描版pdf

• 首先下载ImageMagick并安装，注意勾选Install legacy components (convert.exe etc)
• 然后安装Ghostscript(目的是为了使用convert命令)。
• 将pdf转为图片

• 测试转换效果

• 转为pdf

## Clang查看对象的内存布局

clang可以在编译时使用-cc1 -fdump-record-layouts参数来查看对象的内存布局。

Example:

## 虚函数的默认参数根据调用者(指针或引用)的静态类型决定

C++标准中规定了关于虚函数的默认参数使用描述：

[ISO/IEC 14882:2014]A virtual function call (10.3) uses the default arguments in the declaration of the virtual function determined by the static type of the pointer or reference denoting the object.

## Windwos上使用MinGW编译LLVM

\quad1ememm代表当前字体下接近字符‘M’的宽度(approximately the width of an "M" in the current font).

### 分隔符

$$declaration\textrm{-}specifiers_{opt}$$

## What is Translation Unit in C/C++?

[ISO/IEC 14882:2014]A source file together with all the headers (17.6.1.2) and source files included (16.2) via the preprocessing directive #include, less any source lines skipped by any of the conditional inclusion (16.1) preprocessing directives, is called a translation unit. [ Note: A C ++ program need not all be translated at the same time. — end note ]

[ISO/IEC 9899:1999]
A source file together with all the headers and source files included via the preprocessing directive #include is known as a preprocessing translation unit. After preprocessing, a preprocessing translation unit is called a translation unit.

## 一些cmd命令技巧

cmd命令里是让他们同时执行几个命令：

cmd/c的意思为执行完命令后关闭命令窗口；如果想要执行完不关闭可以使用/k

cmd中让命令在后台执行不会阻塞后续命令的方式(类似于linux命令后加&)：

start加入/b，这两条命令就不会阻塞(不会等到第一条命令执行完毕之后再执行第二条)。

.bat后台执行，有些.bat我们希望开机启动，这时候开机弹出黑框框就不太好，可以使用下面的.vbs脚本来执行.bat

## sendfile的优势

Unix system call interface:sendfile

transfer data between file descriptors

## new、构造函数和异常

new操作实际上是由两个部分组成的：

1. 首先调用operator new分配内存
2. 调用对象的构造函数

Evaluation of a new expression invokes one or more allocation and constructor functions; see 5.3.4

## C++中常见术语错误

WrongRight
Pure virtual base classAbstract class
MethodMember function
Virtual method???
DestructedDestroyed
Cast operatorConversion operator

## 为什么要有引用？

1. 防止对象拷贝带来的开销(比指针的间接访问要更简洁)
2. 对于IO流的使用(比如cout<<x<<y返回流的引用等价于使用cout<<x,cout<<y)

## 并发和并行(concurrency and parallel)

A logical flow whose execution overlaps in time with another flow is called a concurrent flow, and the two flows are said to run concurrently. More precisely, flows X and Y are concurrent with respect to each other if and only if X begins after Y begins and before Y finishes, or Y begins after X begins and before X finishes. For example, in Figure 8.12, processes A and B run concurrently, as do A and C. On the other hand, B and C do not run concurrently, because the last instruction of B executes before the first instruction of C.
The general phenomenon of multiple flows executing concurrently is known as concurrency. The notion of a process taking turns with other processes is also known as multitasking. Each time period that a process executes a portion of its flow is called a time slice. Thus, multitasking is also referred to as time slicing. For example, in Figure 8.12, the flow for Process A consists of two time slices.
Notice that the idea of concurrent flows is independent of the number of processor cores or computers that the flows are running on. If two flows overlap in time, then they are concurrent, even if they are running on the same processor. However, we will sometimes find it useful to identify a proper subset of concurrent flows known as parallel flows. If two flows are running concurrently on different processor cores or computers, then we say that they are parallel flows, that they are running in parallel, and have parallel execution.

## C++一些语言特性被设计的原因

• 名字空间就是针对不同库里使用相同的名字而提供的机制
• 异常处理是为建立一种处理错误的公共模型提供了基础
• 模板是为定义独立于具体类型的容器类和算法而提供的一种机制，其中的具体类型可以由用户或者其他的库提供
• 构造函数和析构函数为对象的初始化和最后清理提供了一种公共模型
• 抽象类提供了一种机制，借助于它可以独立地定义接口，与实际被接口的类无关
• 运行时类型信息是为了寻回类型信息而提供的一种机制，因为当对象被传递给一个库再传递回来的时候，可能只携带着不够特殊(基类的)类型信息。

## 为什么socket的IP地址是一个结构？

The <netinet/in.h> header shall define the in_addr structure, which shall include at least the following member:

in_addr_t Equivalent to the type uint32_t as described in <inttypes.h>.

[CSAPP,2e]把一个标量地址存放在结构中，是socket接口早起实现的不幸产物。为IP地址定义一个标量类型应该更有意义，但是现在更改已经太迟了，因为已经有大量应用基于此了。

## TCP/IP协议族

TCP/IP的协议族是一组不同的协议组合在一起构成的协议族(应用层协议(FTP/Telnet等)、运输层(TCP/UDP)、网络层(IP/ICMP/IGMP)、链路层(设备驱动程序及网络接口设备))。尽管通常称该协议族为TCP/IP，但TCP和IP只是其中的两种协议而已。

## POSIX data types

[IEEE Std 1003.1™ 2008]The implementation shall support one or more programming environments in which the widths of blksize_t, pid_t, size_t, ssize_t, and suseconds_t are no greater than the width of type long.