long exchange (long *xo,long y){
- long x=*xp;
- *xp=y;
- return x;
-}
long exchange(long *xp,long y) xp int %rdi,y in %rsi
-1 exchange:
-2 moveq (%rdi),%rax 取%rdi地址指向的内存空间的值传送给%rax。xp是指针,指针的值在寄存器中,那么解引用指针得出指针指向的值,这个"解引用"的操作映射为(%rdi)
-3 movq %rsi,(%rdi) 作为对比这里不加括号,因为值就存储在%rsi寄存器中,取%rsi寄存器存储的值,移动到%rdi寄存器值所指向的内存中。
-4 ret
pushq S 栈指针减少8(指针大小) 将四字压入栈 因为栈是倒过来画的地址由高到低 等价于 subq $8 ,%rsp movq %rbq,(%rsp) popq D 栈指针加8 将四字弹出 等价于 movq (%rsp),%rax addq $8,%rsp
算数操作 leaq S, D D <-&S 把S的地址传送给D INC D D <-D+1 加1 DEC D D <-D-1 减1 NEG 取负 NOR 取补 ADD 加 SUB S,D D<-D+S 减 IMUL 乘 XOR 异或 OR 或 AND 与 SAL S,D D <-D<<k 左移 SHL 左移同上 SAR 算数右移 SHR 逻辑右移
1.什么是narrow ,widen contract? Wide contract functions have well-defined behavior for all possible inputs, while narrow contracts mean that the functions can only be called when certain preconditions are met. 宽合同对所有可能的输入都有良定义行为,窄合同只有满足某些前提条件才能调用 例如vector的成员函数size()是宽契约,没有前提条件对任何即使被移动后的vector也能使用size()是定义明确的,另外如at()函数对不满足的范围的参数通过抛异常也就是所谓检查,而operator[]则是窄契约调用他的参数需要在范围内否则会引发未定义行为。 2.什么是合同(contract)?使用动机,如何使用,设计历史参考D2899R0 合同是类或函数的正式接口规范,他包含了对法律合同的条件和义务这一概念的隐喻表述。也就是说合同里声明了我需要负责的义务(条件)以及我对满足条件后期望获得的回报。为了和软件中的其他组件互操作我们规定合同。 当函数运行时不满足合同的条件,即会产生bug,这与错误不同。错误可以恢复,但合同需要修改源代码来解决 例如 int unsafe_acess(int i){return arr[i];} 当i小于0或大于max-1时此访问是未定义行为。 通常来说契约有前提条件,这些前提条件需要调用者满足,如上诉函数的输入需要调用者不能传递超过数组边界的大小。 而满足后置条件的责任,则由调用方来掌握。当函数执行时函数返回值,或被修改对象永远保持为真的状态。 如同
That allows implementations to be optimally efficient in time and space. In particular, it allows us to: • place objects of concrete types on the stack, in statically allocated memory, and in other objects (§6.4.2); • refer to objects directly (and not just through pointers or references); • initialize objects immediately and completely (e.g., using constructors; §2.3.2); and copy objects (§3.3)
When we talk about portability of C++ programs, we usually mean portability of source code; that is, the source code can be successfully compiled and run on a variety of systems
The ISO C++ standard defines two kinds of entities: • Core language features, such as built-in types (e.g., char and int) and loops (e.g., for-statements and while-statements) • Standard-library components, such as containers (e.g., vector and map) and I/O operations (e.g., << and getline())
C++ is a statically typed language. That is, the type of every entity (e.g., object, value, name, and expression) must be known to the compiler at its point of use. The type of an object determines the set of operations applicable to it
Every C++ program must have exactly one global function named main(). The program starts by executing that function. The int value returned by main(), if any, is the program’s return value to "the system." If no value is returned, the system will receive a value indicating successful completion.
Every name and every expression has a type that determines the operations that may be performed on it A declaration is a statement that introduces a name into the program. It specifies a type for the named entity: • A type defines a set of possible values and a set of operations (for an object). • An object is some memory that holds a value of some type. • A value is a set of bits interpreted according to a type. • A variable is a named object
A char variable is of the natural size to hold a character on a given machine (typically an 8-bit byte), and the sizes of other types are quoted in multiples of the size of a char. The size of a type is implementation-defined (i.e., it can vary among different machines) and can be obtained by the sizeof operator; for example, sizeof(char) equals 1 and sizeof(int) is often 4
double d = 2.2; //初始化浮点数
-int i = 7; // 初始化整数
-d = d+i; // 求和赋值给d
-i=d∗i; // 将产生的值赋值给i(将双精度浮点数截断转换为整型)
C++ offers a variety of notations for expressing initialization, such as the = used above, and a universal form based on curly-brace-delimited initializer lists
简单的说c++提供了花括号初始化器,是得我们在初始化变量时(定义),可以这么写
double d1 = 2.3;
-double d2 {2.3};
-complex<double> z = 1; // a complex number with double-precision floating-point scalars
-complex<double> z2 {d1,d2};
-complex<double> z3 = {1,2}; // the = is optional with { ... }
-vector<int> v {1,2,3,4,5,6};
We use auto where we don’t hav e a specific reason to mention the type explicitly. ‘‘Specific reasons’’ include: • The definition is in a large scope where we want to make the type clearly visible to readers of our code. • We want to be explicit about a variable’s range or precision (e.g., double rather than float)
C++ supports two notions of immutability (§7.5): • const: meaning roughly "I promise not to change this value"(§7.5). This is used primarily to specify interfaces, so that data can be passed to functions without fear of it being modified. The compiler enforces the promise made by const. • constexpr: meaning roughly"to be evaluated at compile time"(§10.4). This is used primarily to specify constants, to allow placement of data in memory where it is unlikely to be corrupted, and for performance
//Consider copying ten elements from one array to another:
-void copy_fct()
-{
-int v1[10] = {0,1,2,3,4,5,6,7,8,9};
-int v2[10]; // to become a copy of v1
-v2=v1 //error
-for (auto i=0; i!=10; ++i) // copy elements
-v2[i]=v1[i];
-// ...
-}
同时介绍的这个c++11的范围for循环也很有用,我们可以不用指定边界。对于任意序列我们都可以
void print()
-{
-int v[] = {0,1,2,3,4,5,6,7,8,9};
-for (auto x : v) // for each x in v
-cout << x << '\n';
-for (auto x : {10,21,32,43,54,65})
-cout << x << '\n';
-for (auto& x : {10,21,32,43,54,65}) //我不想单纯的复制序列中的元素而是希望引用,使用auto&这样的写法
-cout << ++x << '\n';
-// ...
-}
enum class Color { red, blue , green };
-enum Traffic_light { green, yellow, red };
-int i = Color::red; // 错误不能隐式转换
-Color c = 2; // 错误2不是Color类型
-int b=Traffic_light::red;//可以
Often, a function has no way of completing its assigned task after an exception is thrown.Then, "handling"an exception simply means doing some minimal local cleanup and rethrowing the exception
通常函数无法完成分配任务时需要抛出异常,并且处理剩余的清理工作。异常是RAII的关键概念。
静态断言略过。
\ No newline at end of file
diff --git a/docs/.vuepress/dist/article/jaovy4gg/index.html b/docs/.vuepress/dist/article/jaovy4gg/index.html
deleted file mode 100644
index 31bc671..0000000
--- a/docs/.vuepress/dist/article/jaovy4gg/index.html
+++ /dev/null
@@ -1,90 +0,0 @@
-搭建vscode-cpp环境 | Yuzhiy
name
-预设的名称,一般用表示平台或编译期的版本名字;
-
-vendor
-可选内容,提供供应商的信息,Cmake一般不管除非有所谓映射(不用管)
-
-displayName
-此预设的个性化名词(无关紧要)一般有编译期名字代替如"GCC 15.0.0 x86_64-w64-mingw32"
-
-description
-自定义的描述(无关紧要)一般使用本地编译期所在路径描述
-
-steps
-A required array of objects describing the steps of the workflow. The first step must be a configure preset, and all subsequent steps must be non- configure presets whose configurePreset field matches the starting configure preset. Each object may contain the following fields:
-
-type
-A required string. The first step must be configure. Subsequent steps must be either build, test, or package.
-
-name
-A required string representing the name of the configure, build, test, or package preset to run as this workflow step.