范围问题 [英] Scope question
问题描述
早上好。我有一个问题 - 我真的不确定答案
并希望它不是特定于编译器...我正在写一种语言
翻译器转换成C语言。我希望在C代码中保留一些额外的范围
问题。
因此我想知道是否有好字样;在C中创建一个
作用域的方法 - 当然我可以使用虚拟条件或
之类的东西,但我想知道是否有更好的方法。
干杯,
尼克
Morning all. I have a question - I am really not sure about the answer
and hope that it is not compiler specific... I am writing a language
translator to translate into C. There are some additional scoping
issues in the language which I would like to preserve in the C code.
Because of this I was wondering if there is a "good" way of creating a
scoped block in C - of course I could use a dummy conditional or
something like that, but I was wondering if there is a better way.
Cheers,
Nick
推荐答案
polas说:
polas said:
早上好。我有一个问题 - 我真的不确定答案
并希望它不是特定于编译器...我正在写一种语言
翻译器转换成C语言。我希望在C代码中保留一些额外的范围
问题。
因此我想知道是否有好字样;在C中创建一个
作用域的方法 - 我当然可以使用虚拟条件或
这样的东西,但我想知道是否有更好的方法。
Morning all. I have a question - I am really not sure about the answer
and hope that it is not compiler specific... I am writing a language
translator to translate into C. There are some additional scoping
issues in the language which I would like to preserve in the C code.
Because of this I was wondering if there is a "good" way of creating a
scoped block in C - of course I could use a dummy conditional or
something like that, but I was wondering if there is a better way.
{
}
例如:
int foo(无效)
{
int i; / *我在这里的范围* /
{/ *这引入了一个新的范围,你不需要
一个虚拟条件。 * /
int i; / *这个我在这里的范围,而另一个是
不再可见,因为这个掩盖它* /
/ *这个我即将离开范围* /
}
/ *第一个我现在再次可见* /
-
Richard Heathfield< http://www.cpax.org.uk>
电子邮件:-www。 + rjh @
谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>
Usenet是一个奇怪的放置" - dmr 1999年7月29日
{
}
For example:
int foo(void)
{
int i; /* i is in scope here */
{ /* this introduces a new scope, and you don''t need
a dummy conditional. */
int i; /* this i is in scope here, and the other one is
no longer visible because this one masks it */
/* this i is about to go out of scope */
}
/* the first i is now visible again */
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
polas写道:
polas wrote:
早上全部。我有一个问题 - 我真的不确定答案
并希望它不是特定于编译器...我正在写一种语言
翻译器转换成C语言。我希望在C代码中保留一些额外的范围
问题。
因此我想知道是否有好字样;在C中创建一个
作用域的方法 - 当然我可以使用虚拟条件或
之类的东西,但我想知道是否有更好的方法。
干杯,
尼克
Morning all. I have a question - I am really not sure about the answer
and hope that it is not compiler specific... I am writing a language
translator to translate into C. There are some additional scoping
issues in the language which I would like to preserve in the C code.
Because of this I was wondering if there is a "good" way of creating a
scoped block in C - of course I could use a dummy conditional or
something like that, but I was wondering if there is a better way.
Cheers,
Nick
代码中的任何地方都可以创建块范围。
....
{
本地变量
语句
}
该块中的局部变量只能在那个bloack中看到
。你不需要有条件的打开
a区块。
Anywhere in your code you can create a block scope.
....
{
local variables
statements
}
the local variables in that block will be only visible
in that bloack. You do not need a conditional to open
a block.
9月20日,10:15,jacob navia< ja ... @ jacob.remcomp.frwrote:
On 20 Sep, 10:15, jacob navia <ja...@jacob.remcomp.frwrote:
polas写道:
polas wrote:
早上全部。我有一个问题 - 我真的不确定答案
并希望它不是特定于编译器...我正在写一种语言
翻译器转换成C语言。我希望在C代码中保留一些额外的范围
问题。
因此我想知道是否有好字样;在C中创建一个
作用域的方法 - 我当然可以使用虚拟条件或
这样的东西,但我想知道是否有更好的方法。
Morning all. I have a question - I am really not sure about the answer
and hope that it is not compiler specific... I am writing a language
translator to translate into C. There are some additional scoping
issues in the language which I would like to preserve in the C code.
Because of this I was wondering if there is a "good" way of creating a
scoped block in C - of course I could use a dummy conditional or
something like that, but I was wondering if there is a better way.
干杯,
尼克
Cheers,
Nick
你身边的任何地方代码你可以创建一个块范围。
...
{
本地变量
声明
}
该块中的局部变量只能在那个bloack中显示
。你不需要有条件的打开
一个块。
Anywhere in your code you can create a block scope.
...
{
local variables
statements
}
the local variables in that block will be only visible
in that bloack. You do not need a conditional to open
a block.
非常感谢Richard和Jacob的帮助 - 我从未意识到
可以创建一个块
尼克
Thats great thanks for the help Richard and Jacob - I never realised
that a block could be created that way
Nick
这篇关于范围问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!