就现代操作系统而言都是保护模式了,程序 A 不可能直接访问程序 B 的内存地址啊……
都是逻辑地址,要通过操作系统做转换的,A 不需要知道 B 的物理地址,也就不会溢出啊。
没有足够的数据
(゚∀゚ )
暂时没有任何数据
(゚∀゚ )
暂时没有任何数据
Amelie 赞了回答 · 2020-12-04
就现代操作系统而言都是保护模式了,程序 A 不可能直接访问程序 B 的内存地址啊……
都是逻辑地址,要通过操作系统做转换的,A 不需要知道 B 的物理地址,也就不会溢出啊。
就现代操作系统而言都是保护模式了,程序 A 不可能直接访问程序 B 的内存地址啊……都是逻辑地址,要通过操作系统做转换的,A 不需要知道 B 的物理地址,也就不会溢出啊。
关注 1 回答 1
Amelie 关注了标签 · 2020-12-02
网络系统的硬件、软件及其中数据受到保护,不受偶然的或者恶意的破坏、更改、泄露,保证系统连续可靠地运行,网络服务不中断的措施。
网络系统的硬件、软件及其中数据受到保护,不受偶然的或者恶意的破坏、更改、泄露,保证系统连续可靠地运行,网络服务不中断的措施。
关注 50983
Amelie 提出了问题 · 2020-12-02
32位的情况,指针只有4字节大小,能访问 4G 的空间。
两个程序A和B运行,都分配 4G 的虚拟地址空间
那 A程序 如何访问 B程序 的内存地址呢?
4字节指针好像只能表示自己 4G 空间的地址吧?
32位的情况,指针只有4字节大小,能访问 4G 的空间。两个程序A和B运行,都分配 4G 的虚拟地址空间那 A程序 如何访问 B程序 的内存地址呢?4字节指针好像只能表示自己 4G 空间的地址吧?
关注 1 回答 1
Amelie 赞了回答 · 2020-11-29
就是给变量初始化用的,c++新标准出的骚语法了
就是给变量初始化用的,c++新标准出的骚语法了
关注 3 回答 2
Amelie 提出了问题 · 2020-11-29
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("%x\n", (unsigned int)(unsigned char)0x80);
printf("%x\n", (unsigned int)(signed char)0x80);
return 0;
}
输出:
80
ffffff80
第一个输出80
可以理解,毕竟是从0x80
转换为无符号int。
第二个输出ffffff80
我无法理解,从1字节数据扩展为4字节数据,并且是扩展到无符号类型,为什么符号位也跟着扩展了?
P.S. C/C++中输出结果一致
第一个输出80可以理解,毕竟是从0x80转换为无符号int。第二个输出ffffff80我无法理解,从1字节数据扩展为4字节数据,并且是扩展到无符号类型,为什么符号位也跟着扩展了?
关注 2 回答 1
Amelie 赞了回答 · 2020-11-28
int a{3};
int a[3]{1,2,3};
std::string str{"123"};
当然里面也可以啥都没有(这种情况用()
有时会被当做函数声明,此时只能用 {}
)
int a{};
int a[3]{};
std::string str{};
然后变量名是可以没有的(生成一个临时变量/对象)。这种单独放一个语句一般没什么用,除非想利用构造/析构的副作用。但是可以用作函数的参数。:
int {};
(int [3]){}; // 没 () 会被认成 structured binding
std::string{};
initialization {代码...} 当然里面也可以啥都没有(这种情况用()有时会被当做函数声明,此时只能用 {}) {代码...} 然后变量名是可以没有的(生成一个临时变量/对象)。这种单独放一个语句一般没什么用,除非想利用构造/析构的副作用。但是可以用作函数的参数。: {...
关注 3 回答 2
Amelie 提出了问题 · 2020-11-27
在网上看到了这么一个例子:
#include <iostream>
using namespace std;
int main()
{
// 不懂下面这句语句的含义
double {};
return 0;
}
double {}
是什么语法?
我用std::is_same
判断类型是(double)0.0
,但是没见过这种语法。
在网上看到了这么一个例子: {代码...} double {}是什么语法?我用std::is_same判断类型是(double)0.0,但是没见过这种语法。
关注 3 回答 2
Amelie 赞了回答 · 2020-08-08
The ambiguity arising from the similarity between a function-style cast and a declaration mentioned in [stmt.ambig] can also occur in the context of a declaration. In that context, the choice is between a function declaration with a redundant set of parentheses around a parameter name and an object declaration with a function-style cast as the initializer. Just as for the ambiguities mentioned in [stmt.ambig], the resolution is to consider any construct that could possibly be a declaration a declaration. [ Note: A declaration can be explicitly disambiguated by adding parentheses around the argument. The ambiguity can be avoided by use of copy-initialization or list-initialization syntax, or by use of a non-function-style cast. — end note ] [ Example:
struct S { S(int); }; void foo(double a) { S w(int(a)); // function declaration S x(int()); // function declaration S y((int(a))); // object declaration S y((int)a); // object declaration S z = int(a); // object declaration }
— end example ]
An ambiguity can arise from the similarity between a function-style cast and a type-id_. The resolution is that any construct that could possibly be a type-id in its syntactic context shall be considered a type-id_. [ Example:
template <class T> struct X {}; template <int N> struct Y {}; X<int()> a; // type-id X<int(1)> b; // expression (ill-formed) Y<int()> c; // type-id (ill-formed) Y<int(1)> d; // expression void foo(signed char a) { sizeof(int()); // type-id (ill-formed) sizeof(int(a)); // expression sizeof(int(unsigned(a))); // type-id (ill-formed) (int())+1; // type-id (ill-formed) (int(a))+1; // expression (int(unsigned(a)))+1; // type-id (ill-formed) }
— end example ]
string()
, string("str")
,string(a)
,在 C++ 语法结构里,都属于 function style cast 。
当 function style cast 与 declaration(声明) 出现出现歧义的时候,认为是 declaration。
当 function style cast 与 type id 出现歧义的时候,认为是 type id
string()
可以被认成一个函数类型(type id),返回值是 string
,没有参数,然后由于位于函数参数位置,被当作函数指针使用
string()
认为是 function style cast,那么 Print p(string())
是变量声明。
string()
认为是 type id ,那么 Print p(string())
是一个函数。(想想 Print p(int)
。int
也是一个 type id)
两者均合法,有歧义,认为 string()
是 type id ,p
是一个函数。
The ambiguity arising from the similarity between a function-style cast and a declaration mentioned in [stmt.ambig] can also occur in the context of a declaration. In that context, the choice is between a function declaration with a redundant set ...
关注 3 回答 1
Amelie 收藏了问题 · 2020-08-08
#include <iostream>
#include <string>
using namespace std;
struct Print {
template<typename T>
Print(T t){
cout<<(t+=10);
}
};
int main()
{
// 这句为什么是一句函数声明而不是变量创建?
Print p(string());
return 0;
}
clang++ 10.0.0提示:
`warning: parentheses were disambiguated as a function declaration`
为什么会这样,我觉得string()
是创建了一个临时量,这应该是个变量创建才对,为什么编译器会认为是个函数声明呢?
PS.不要吐槽代码,这是一道题 :>
{代码...} clang++ 10.0.0提示: {代码...} 为什么会这样,我觉得string()是创建了一个临时量,这应该是个变量创建才对,为什么编译器会认为是个函数声明呢?PS.不要吐槽代码,这是一道题 :>
查看全部 个人动态 →
(゚∀゚ )
暂时没有
(゚∀゚ )
暂时没有
注册于 2017-09-07
个人主页被 806 人浏览
推荐关注