小编Mod*_*e77的帖子

stithed文件在`git status`中显示为未更改(git v.2.16.0)

我使用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)

git git-for-windows

11
推荐指数
1
解决办法
148
查看次数

返回本地创建的const char*

#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超出范围.

有人可以详细解释这里发生了什么吗?

c++ pointers return lifetime

5
推荐指数
1
解决办法
543
查看次数

4
推荐指数
1
解决办法
3469
查看次数

如何排除嵌套的循环?

通常,我需要对一组类数据进行批量操作。考虑以下类:

#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++

4
推荐指数
1
解决办法
86
查看次数

我对这个程序集的理解正确吗?

源代码是 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)

x86 assembly gcc

2
推荐指数
1
解决办法
66
查看次数

对于速度关键的应用程序来说,DLL 通常不是理想的选择吗?

到目前为止,我只编写和构建过静态库,因此,我对共享库场景(或 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_Typelib_function()是在 DLL 中定义的,应用程序是否会加载库来调用lib_function(),在调用后卸载,然后再次加载以调用 的构造函数My_Lib_Type?如果这就是它的工作原理,那么这个切换过程有多快?

c++ dll

1
推荐指数
1
解决办法
57
查看次数

使用typedef作为促进替代类名的方式是否被滥用?

在我的C ++库中,在许多模块中,我typedef都是这样使用的:

class ClassName {
//...
}

typedef ClassName AlternateClassName;
Run Code Online (Sandbox Code Playgroud)

我这样做只是为了使自己以及可能的其他人允许我的班级使用其正式名称以外的名称进行调用-只是同义词。这可以使用typedef吗?

c++ typedef

0
推荐指数
1
解决办法
71
查看次数

a,&a和&a [0]之间的类型区别是什么?

#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个有什么区别?

c++

-1
推荐指数
1
解决办法
173
查看次数

四舍五入的数学函数

什么(rounding/=10.0;)意思 为什么会有斜线?

c++ arduino

-5
推荐指数
1
解决办法
63
查看次数