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 12 1253
polas said:
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.
{
}
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 wrote:
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
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.
On 20 Sep, 10:15, jacob navia <ja...@jacob.remcomp.frwrote:
polas wrote:
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
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.
Thats great thanks for the help Richard and Jacob - I never realised
that a block could be created that way
Nick
polas wrote:
On 20 Sep, 10:15, jacob navia <ja...@jacob.remcomp.frwrote:
>polas wrote:
>>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
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.
Thats great thanks for the help Richard and Jacob - I never realised
that a block could be created that way
It's nice when Richard and Jacob agree with each other. It doesn't seem like it
happens very often round here...
Phil
--
Philip Potter pgp <atdoc.ic.ac.uk
Philip Potter wrote:
polas wrote:
>On 20 Sep, 10:15, jacob navia <ja...@jacob.remcomp.frwrote:
>>polas wrote: 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 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.
Thats great thanks for the help Richard and Jacob - I never realised that a block could be created that way
It's nice when Richard and Jacob agree with each other. It doesn't seem
like it happens very often round here...
Phil
Well, he *is* an authority in technical things. I would not discuss
that.
Philip Potter said:
<snip>
It's nice when Richard and Jacob agree with each other.
Don't count on it. I haven't seen Mr Navia's reply, so I can't tell whether
I agree with him or not.
It doesn't seem like it happens very often round here...
Since he's in my killfile, that's not very surprising. He's there because
he was wrong so often that people got fed up with my correcting him. Now
that I've killfiled him, /they/ have to correct him - which they have had
to do rather a lot.
I'd be surprised (and delighted) if his reply in this thread were devoid of
inaccuracies.
--
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
Richard Heathfield <rj*@see.sig.invalidwrites:
Philip Potter said:
<snip>
>It's nice when Richard and Jacob agree with each other.
Don't count on it. I haven't seen Mr Navia's reply, so I can't tell whether
I agree with him or not.
>It doesn't seem like it happens very often round here...
Since he's in my killfile, that's not very surprising. He's there because
he was wrong so often that people got fed up with my correcting him. Now
that I've killfiled him, /they/ have to correct him - which they have had
to do rather a lot.
I'd be surprised (and delighted) if his reply in this thread were devoid of
inaccuracies.
It is such a shame that someone with your undoubted skills in C should
take such delight in being such a vindictive person. Jacob is frequently
helpful and practical to many posters. He doesn't sneer or talk down to
anyone. Should you ever make that position available, I doubt if he
would take it.
On Thu, 20 Sep 2007 14:21:53 +0200, Richard wrote:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Philip Potter said:
<snip>
>>It's nice when Richard and Jacob agree with each other. It doesn't seem like it happens very often round here...
Since he's in my killfile, that's not very surprising. He's there because he was wrong so often that people got fed up with my correcting him. Now that I've killfiled him, /they/ have to correct him - which they have had to do rather a lot.
I'd be surprised (and delighted) if his reply in this thread were devoid of inaccuracies.
It is such a shame that someone with your undoubted skills in C should
take such delight in being such a vindictive person. Jacob is frequently
helpful and practical to many posters.
Is he? He's in my killfile too, but in the stuff I read written by
him and quoted by others, the one in this thread are the first
ones really useful (for someone who doesn't have lcc-win32, at
least) since weeks.
He doesn't sneer or talk down to anyone.
Doesn't he anymore? Good news...
--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid “Smart Quotes” feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen
On Thu, 20 Sep 2007 11:38:11 +0000, Richard Heathfield wrote:
Philip Potter said:
<snip>
>It's nice when Richard and Jacob agree with each other.
[snip]
I'd be surprised (and delighted) if his reply in this thread were devoid of
inaccuracies.
To be honest (because I am too good a person, rather than because
I think he deserves that), I temporarily turned the filter off,
and I saw that JN's post was entirely quoted by polas. Apart from
a typo there is nothing wrong with it. Strange but true...
--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid “Smart Quotes” feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen
Army1987 said:
On Thu, 20 Sep 2007 11:38:11 +0000, Richard Heathfield wrote:
>Philip Potter said:
<snip>
>>It's nice when Richard and Jacob agree with each other.
[snip]
>I'd be surprised (and delighted) if his reply in this thread were devoid of inaccuracies.
To be honest (because I am too good a person, rather than because
I think he deserves that), I temporarily turned the filter off,
and I saw that JN's post was entirely quoted by polas. Apart from
a typo there is nothing wrong with it. Strange but true...
If that is the case (and Polas has omitted nothing from that quote), then
the reply is indeed inaccurate, as I had feared, although it was such a
trivial question that it was difficult to get it terribly wrong.
Mr Navia's claim, "Anywhere in your code you can create a block scope." is
simply not true, and it is so trivial to demonstrate this that I would not
think it inappropriate to hand the proof to first-week C students as an
exercise.
--
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
Army1987 said:
On Thu, 20 Sep 2007 14:21:53 +0200, Richard wrote:
<snip>
>It is such a shame that someone with your undoubted skills in C should take such delight in being such a vindictive person. Jacob is frequently helpful and practical to many posters.
Is he?
No, but then neither is Richard Riley. Last I checked, he restricted his
activities to criticising the helpful rather than trying to be helpful
himself. For that reason, Mr Riley, too, is in my killfile. From your
quote, it is evident that this does not prevent him making lousy
deductions and outrageous claims, but hey, life's too short to spend it
fighting with bozos.
<snip>
--
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
On Thu, 20 Sep 2007 15:39:55 +0000, Richard Heathfield wrote:
Mr Navia's claim, "Anywhere in your code you can create a block scope." is
simply not true, and it is so trivial to demonstrate this that I would not
think it inappropriate to hand the proof to first-week C students as an
exercise.
Probably he didn't really mean *that* by "anywhere", but...
Ok, finding something correct written by him is even harder than
I imagined.
--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid “Smart Quotes” feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Arthur |
last post by:
>>>a=
>>> for p in a:
print p
1
2
3
>>> p
3
My naive expectation was that p would be 'not defined' from outside
|
by: Razvan |
last post by:
Hi,
I took a C++ test and I found the following question:
Q. Inside a class member function definition, which scope is searched
|
by: Vipul Jain |
last post by:
Can any one please tell me what is the difference between global
scope of an variable and file scope of an variable.
Vipul
|
by: Gery D. Dorazio |
last post by:
Gurus,
If a static variable is defined in a class what is the scope of the variable
resolved to for it to remain 'static'? For instance, lets say I create a
class library assembly that is...
|
by: Dieter |
last post by:
Hi.
In the snippet of code below, I'm trying to understand why when the
struct dirent ** namelist
is declared with "file" scope, I don't have a problem freeing the
allocated memory. But...
|
by: Frank Silvermann |
last post by:
I have taken an extraordinary leap into the modern world by purchasing
webspace. In addition to my private concerns, I would like to make a
part to which others, e.g. my nieces and ex-wife, can...
|
by: Christian Christmann |
last post by:
Hi,
I've a a question on the specifier extern.
Code example:
void func( void )
{
extern int e;
//...
|
by: Michael |
last post by:
Hello, I have a newbie question about class scope. I am writting a little
program that will move files to one of two empty folders. I am having a hard
time understanding scope. So this will be a...
|
by: David |
last post by:
I feel like an idiot asking this but here goes: I understand the 'concept'
of scope and passing data by value and/or by reference but I am confused on
some specifics.
class example{
int i; //my...
|
by: somenath |
last post by:
Hi All ,
I have one question regarding scope and lifetime of variable.
#include <stdio.h>
int main(int argc, char *argv)
{
int *intp = NULL;
char *sptr = NULL;
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |