我使用git换窗户v2.16.0和遇到以下问题,ALSE报道在这里:
我最初的工作状态很干净; 输出'git status':
git status
On branch beta
nothing to commit, working tree clean
Run Code Online (Sandbox Code Playgroud)
然后我进行局部更改.产量git status
:
git status
On branch beta
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: app/src/main/java/android_serialport_api/sample/Debug.java
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)
然后我用'git stash'藏匿它们:
git stash
Saved working directory and index state WIP on beta: 2fca403 …
Run Code Online (Sandbox Code Playgroud) #include <iostream>
const char* fun()
{
const char* x = "abc";
std::cout << "x = " << x << "\n";
return x;
}
int main(int arc, char** argv)
{
const char* y = fun();
std::cout << "y = " << y << "\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在我的机器上运行它给出:
x = abc
y = abc
Run Code Online (Sandbox Code Playgroud)
在fun()
,x
(一个局部变量)被分配字面创建本地一个字符串的地址,然而,当该函数返回时,该数据指向y
是作为通过指向同一x
即使x
超出范围.
有人可以详细解释这里发生了什么吗?
通常,我需要对一组类数据进行批量操作。考虑以下类:
#include <vector>
class Component {
public:
bool isFixed;
int a, b, c;
Component():
isFixed(false),
a(0), b(0), c(0)
{}
};
class System {
public:
std::vector<Component> components;
System(int numComponents):
components(numComponents)
{}
};
class Universe {
public:
std::vector<System> systems;
Universe(int numSystems, int numComponents):
systems(numSystems, System(numComponents))
{}
};
Run Code Online (Sandbox Code Playgroud)
现在,做一个操作的每Component
一个Universe
成为通过所有循环的问题Component
所有的第System
在A S Universe
:嵌套for
循环。
// Fixes a Component.
//
void fixComponent(Component& c) {c.isFixed = true;}
// Adds a number to the pieces of a Component. …
Run Code Online (Sandbox Code Playgroud) 源代码是 C,我使用 gcc 11.1 编译它并禁用优化(-O0)。程序集的链接在这里,因此您可以自己查看。
我已经用我认为正在发生的事情和“??”注释了程序集。对于线路我不太确定。
现在,我只关心main()
和someAlgebra()
,因此,我在程序集列表中只注意到了这些位。
C源
#include <stdio.h>
const char *MY_LIST[] = {
"of",
"the",
"four",
"green",
"houses",
"one",
"hides",
"five",
"amazing",
"secrets"
};
int someAlgebra(int x, int y)
{
int a = 4;
int b = 3;
return 2*x + 3*y + a - b;
}
void printAll(const char *the_list[], unsigned length)
{
for(unsigned i = 0; i < length; i++) {
puts(the_list[i]);
}
}
int main(int argc, char *argv[])
{ …
Run Code Online (Sandbox Code Playgroud) 到目前为止,我只编写和构建过静态库,因此,我对共享库场景(或 DLL,因为它们在 Windows 上被称为 DLL)还是个新手。
据我了解,DLL 的主要功能是,当应用程序调用库时,库代码会从应用程序中“加载”和“卸载”。因此,我的问题是,这种动态加载和卸载(通常)是否会使 DLL 对于速度关键型应用程序来说不理想?
例如,考虑这个 C++ 片段:
int x = 4;
lib_function(x);
non_lib_function();
My_Lib_Type foo(4, 3);
Run Code Online (Sandbox Code Playgroud)
假设My_Lib_Type
和lib_function()
是在 DLL 中定义的,应用程序是否会加载库来调用lib_function()
,在调用后卸载,然后再次加载以调用 的构造函数My_Lib_Type
?如果这就是它的工作原理,那么这个切换过程有多快?
在我的C ++库中,在许多模块中,我typedef
都是这样使用的:
class ClassName {
//...
}
typedef ClassName AlternateClassName;
Run Code Online (Sandbox Code Playgroud)
我这样做只是为了使自己以及可能的其他人允许我的班级使用其正式名称以外的名称进行调用-只是同义词。这可以使用typedef
吗?
#include <iostream>
void arrayFunctionA(int* p)
{
}
int main()
{
int a[3] = {7, 7, 7};
arrayFunctionA(a);
arrayFunctionA(&a[0]);
arrayFunctionA(&a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这将无法编译,并出现错误arrayFunctionA(&a);
.
所以,a
并&a[0]
评估为int*
,但&a
没有.
这3个有什么区别?