标签: local-variables

为什么我不能在未初始化的局部变量上放置断点?

为什么我不能在线下断点String a;

public void localMethod() {
    String a;
    a = "haha";
    System.out.println(a);
}
Run Code Online (Sandbox Code Playgroud)

我知道局部变量在显式为其赋值之前不会被初始化。但它只是一行代码,它做了一些事情。为什么我不能停在那里?哪些行可以作为断点?

我使用的是Eclipse,jdk6_31

java breakpoints local-variables

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

在x86汇编中,什么时候应该使用全局变量而不是局部变量?

我正在使用 x86 汇编创建一些小程序,这是我第一次使用低级语言,所以我不习惯。

在高级语言中我很少使用全局变量,但是我看过很多在汇编中使用全局变量的教程,所以我不确定何时使用全局变量而不是局部变量。

全局变量是指在 .bss 和 .data 段中创建的数据,局部变量是指使用堆栈指针在当前过程的堆栈上分配的数据。

现在,我使用局部变量和参数比全局变量多得多。

提前致谢。

x86 assembly global-variables local-variables i386

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

在 Lua 中使用其块之外的局部变量?

我有一个嵌套if在Lua中。我在第二if层中有一个变量,我想在第一层中使用它。

变量是npcSpecimen.

if conditions then
  local npcType = util.pickRandom(self.npcTypes)
  local npcSpecimen = "" 
  
  if npcType == "spacebandit" then
    local npcSpecimen = util.pickRandom(self.npcSpecies)
  else
    local npcSpecimen = util.pickRandom(self.npcSpeciesMutant)
  end

  local npcId = space.spawnNpc(spawnPosition, npcSpecimen, npcType)
end
Run Code Online (Sandbox Code Playgroud)

如果以这种方式编写,npcSpecimen则将保持为空,因为 中设置的变量if npcType仅保留在该块中。因此,为了缓解这个问题,我可以使用全局变量来代替:

  if npcType == "spacebandit" then
    npcSpecimen = util.pickRandom(self.npcSpecies)
  else
    npcSpecimen = util.pickRandom(self.npcSpeciesMutant)
  end
Run Code Online (Sandbox Code Playgroud)

然而,根据文档,使用全局变量不是最佳实践,而且速度较慢。

那么,解决这个问题的最佳方法是什么,以便我可以传递npcSpecimennpcId

variables lua if-statement local-variables

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

iPython locals() 中的“_oh”是什么?以及如何在标准 python IDLE 中恢复当地人或创建新的当地人

我正在研究 IPython (Spyder) 中的命名空间,并尝试看看如果我dict.clear() locals(). 所以,事不宜迟:

Python 3.8.5 (default, Aug  5 2020, 09:44:06) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 7.19.0 -- An enhanced Interactive Python.

In [1]: locals().clear()

In [2]: locals
Traceback (most recent call last):

  File "<ipython-input-2-f1c14746c80d>", line 1, in <module>
    locals

  File "C:\Users\sayan\Anaconda3\envs\tfgpu_py38\lib\site-packages\IPython\core\displayhook.py", line 263, in __call__
    self.update_user_ns(result)

  File "C:\Users\sayan\Anaconda3\envs\tfgpu_py38\lib\site-packages\IPython\core\displayhook.py", line 201, in update_user_ns
    if self.cache_size and result is not self.shell.user_ns['_oh']:

KeyError: '_oh'


In [3]: dict
Traceback (most …
Run Code Online (Sandbox Code Playgroud)

python namespaces local-variables ipython python-3.x

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

在局部作用域中使用 extern 取消全局变量的阴影是否有效?

extern嵌套局部作用域中的此声明是将全局a带回作用域的有效且已定义的方法吗?

int a = 1; // may be in another file
void main() {
    int a = 2; // hides the global
    {
     cout << a << endl;  // prints 2
     cout << ::a << endl; // obviously 1
     extern int a;
     cout << a << endl;  // also prints 1
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ global-variables local-variables extern

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

对输出感到困惑

为什么printf打印7虽然变量a是函数fun()的局部变量,但是一旦控件从函数fun()返回,它就不再存在了.

这是c代码

?#include<stdio.h>

main()
{
    int *fun();
    int *c=fun();
    printf("%d",*c);
    getch();
}

int *fun()
{
    int a=7;
    return(&a);
}
Run Code Online (Sandbox Code Playgroud)

输出:7

c printf local-variables

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

Python调用与命名参数同名的函数

在模块中,我有两个功能,让我们给他们打电话fg. g采用命名参数f.我想f从里面打电话g.我如何访问该功能f?不幸的是,由于兼容性问题,我无法更改其名称.

编辑

澄清一下,这就是我的意思:

def f():
  ... code ...

def g(f=1):
  ... code ...
  x = f() # error, f doesn't name the function anymore
  ... code ...
Run Code Online (Sandbox Code Playgroud)

python scope function global-variables local-variables

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

在Delphi 7中将局部变量从一个过程发送/传递到另一个过程?

如何将过程中的局部变量发送/传递给delphi中的另一个过程?

procedure TForm1.Button1Click(Sender: TObject);
var
a,b:integer;
c: array [o..3] smallint;
begin
  a:=1;
  b:=2;
end;
Run Code Online (Sandbox Code Playgroud)

我想将一个或多个已经有值的局部变量(a,b,c)发送到另一个过程,以便在那里使用它们:

procedure TForm1.Button2Click(Sender: TObject);
var
  d:integer;
begin
  d:=a*b;
end;
Run Code Online (Sandbox Code Playgroud)

delphi local-variables delphi-7

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

返回局部变量的引用

在以下代码中,演示了两个函数.f1()返回函数作用域中初始化局部变量的引用,f2()返回函数作用域中初始化局部变量的值.

f2()预计会运行良好,因为本地初始化变量.值从堆栈传递到main.

f1()不会起作用,因为局部变量的引用在函数范围之外是无用的.但是,两个函数的输出似乎都没问题.

这是测试代码;

#include <iostream>
using namespace std;

// function declarations
int& f1();
int f2();

int main()
{
    cout << "f1: " << f1() << endl; // should not work!
    cout << "f2: " << f2() << endl; // should work

    return 0;
}

int& f1()       // returns reference
{
    int i = 10; // local variable

    return i;   // returns reference
}

int f2()        // returns value
{
    int i = 5;  // local variable

    return i;   // …
Run Code Online (Sandbox Code Playgroud)

c++ reference local-variables return-by-reference return-by-value

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

字符串X,Y之间的差异; 和字符串X,字符串Y;

至于内存,使用以下两个选项创建局部变量之间有什么区别:

选项1)

private String A, B;

选项2)

private String A; private String B;

java local-variables

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