Accessing a global variable when there is a local variable in the same name

M

Mohanasundaram

You Dan idiot mind your language. I am not asking you to give me the
answer now. I am talking about your original posting. Dont think than
you are the great in the world. Stop being rude and stop using foul
language.
 
M

Mohanasundaram

And I'd recommend to
other posters, particularly newbies, that if you see us going off
track in discussing something you've asked about, please jump in early
and clarify what you really meant.

[Mohan] Hi Thomson, Thanks for your explanation. I should have jumped
in in early stage and should have clarified what I really meant. But I
could not do that because last week i was not well and did not come to
office. But what made me upset was Dan's rudeness. If newbies want to
clarify something which is not easily found in book or want a expert
comment the only place is this group. This is to share our knowledge
and help people learn C. If people like Dan behave like this then new
comers will stamp this group as the one with a bunch or rude people
who call themselves as experts.

Regards,
Mohan.
 
K

Keith Thompson

And I'd recommend to
other posters, particularly newbies, that if you see us going off
track in discussing something you've asked about, please jump in early
and clarify what you really meant.

[Mohan] Hi Thomson, Thanks for your explanation.

You're welcome.

BTW, my last name is spelled Thompson, but just call me Keith.
 
D

Dan Pop

In said:
The intent of Mohanasundaram's original question was to ask whether C
has an operator that provides access to declarations in outer scopes
that are otherwise hidden. (That wasn't entirely clear from his
original question, but it's very clear now that he's come back and
clarified it.)

That was not clear *at all* from his original question:

int i = 10;
int main()
{
int i = 20;
return 0;
}

Hi All,

I want to access the global variable i inside the main. Is there
a way to do this in C?

How can you read "Is there a way to do this in C?" as "Does C provide any
scope resolution operator?" ? Am I English impaired or what? The
questions asks for a solution *without* imposing *anything* on that
solution, as in "Is there an operator for doing that in C?".

The OP's "clarification" is actually a *completely* different question.
And I would answer with another question: why would C need a scope
resolution operator?
There are such operators in some other languages (C++
and Perl have "::", Ada has ".", and I'm sure there are plenty of
other examples).

Languages that *need* such an operator (for one *good* reason or another).
In C, all you have to do to access the "global" variable is not to
reuse its name. Couldn't be simpler than that.
The question might have been clearer if he had
mentioned C++'s "::" operator, but this is, after all, a C newsgroup.

So what? It is current practice to include references to other
programming languages in questions, to make your intent clearer to those
familiar to those languages.
The underlying question was actually a very good one, regardless of
the fact that the answer happens to be "no".

I don't think so, as long as it was about a feature that C doesn't need
in the first place. If you're aware of any *good* use for a scope
resolution operator in C, please elaborate.

Dan
 
K

Keith Thompson

How can you read "Is there a way to do this in C?" as "Does C provide any
scope resolution operator?" ? Am I English impaired or what? The
questions asks for a solution *without* imposing *anything* on that
solution, as in "Is there an operator for doing that in C?".

I already said that the original question was unclear. I did manage
to figure out the intent before the OP posted his followup; I ascribe
that mostly to luck and to the fact that I spent many years
programming in Ada, a language that does have a scope resolution
mechanism.

I believe that the lack of clarity in the original question was an
innocent oversight, not an indication that the original poster is an
idiot, but I don't care to argue the point.
The OP's "clarification" is actually a *completely* different question.
And I would answer with another question: why would C need a scope
resolution operator?

It probably doesn't. I said that C lacks such a mechanism; I never
said that it needs one.
 
M

Mark McIntyre

office. But what made me upset was Dan's rudeness.

Don't waste your time and energy being upset about that - Dan has the
social skills of a skunk, and treats everyone that way.

He is however a C expert, and rarely wrong, once you pick your way through
the insults, contempt and overweening self-esteem
 
K

kal

You Dan <expletive> mind your language.

Now, now! There is no need for that.

Your original question should have been:
"Is there a scope resolution operator in C?"

The answer is NO. If you think about it (it took me a
while but then I am slow) you will see that there is
no need for such an operator in C.

No inheritance hence no need for scope resolution!

It seems that those who decide upon C specifications are
more apt to apply Occam's razor than not. Which, IMHO,
is just as well.

I suspect that the interviewer was interested not in the
answer itself but rather if you have grasped the concepts
of C++.

<OT>
Your satement, referred to above, is also poorly phrased.
A more indiomatic version would be:
"Mohanasundaram, you <expletive>, mind your tongue!"
</OT>
 
D

Dan Pop

In said:
(e-mail address removed) (Dan Pop) writes:
[...]
How can you read "Is there a way to do this in C?" as "Does C provide any
scope resolution operator?" ? Am I English impaired or what? The
questions asks for a solution *without* imposing *anything* on that
solution, as in "Is there an operator for doing that in C?".

I already said that the original question was unclear.

Wrong, it was crystal-clear. Show me what part of it was phrased in
unclear terms.
I believe that the lack of clarity in the original question was an
innocent oversight,

There was no lack of clarity in the original question, unless you can
point out where exactly it was unclear.

The OP posted a clearly formulated question. It's no one else's
fault that his clearly formulated question did not match his intent.
It probably doesn't. I said that C lacks such a mechanism; I never
said that it needs one.

You *implied* it, when mentioning other languages having it, without
pointing out that C doesn't need have it because there is no need for it.

Dan
 
K

Keith Thompson

Dan, we're we're having a conversation here, not writing a standard.
You insist on nit-picking every little nuance, even when the intent is
perfectly clear to anyone who's willing to pay some attention. It's a
waste of everybody's time.
 
M

Mohanasundaram

Your original question should have been:
"Is there a scope resolution operator in C?"

The answer is NO. If you think about it (it took me a
while but then I am slow) you will see that there is
no need for such an operator in C.

No inheritance hence no need for scope resolution!

It seems that those who decide upon C specifications are
more apt to apply Occam's razor than not. Which, IMHO,
is just as well.

I suspect that the interviewer was interested not in the
answer itself but rather if you have grasped the concepts
of C++.

Hi Dan,

Thanks a lot for your wonderful explanation. Thanks a lot.

Regards,
Mohan.
 
D

Dan Pop

In said:
Dan, we're we're having a conversation here, not writing a standard.
You insist on nit-picking every little nuance, even when the intent is
perfectly clear to anyone who's willing to pay some attention.

Please explain how you can deduce this perfectly clear intent using as
input the original post and nothing else. I am all ears.
It's a waste of everybody's time.

I'm afraid you're wasting everybody's time with a claim that cannot be
supported.

Dan
 
K

Keith Thompson

Please explain how you can deduce this perfectly clear intent using as
input the original post and nothing else. I am all ears.


I'm afraid you're wasting everybody's time with a claim that cannot be
supported.

Dan, if you really want to discuss this further, send me an e-mail and
we can do so privately. I'm not going to continue this in the
newsgroup. (I might change my mind if someone other than you
specifically asks that we discuss it in the newsgroup.)
 
D

Dan Pop

In said:
Dan, if you really want to discuss this further, send me an e-mail and
we can do so privately.

If you have anything to say, say it here, the discussion is still topical.
Whoever lost interest has already killfiled the thread.

Since you don't seem to get it, here is an analogy that could make things
easier for you to understand:

OP: How can I write a C program to display the message "Hello world"?

Responder:

#include <stdio.h>

int main()
{
printf("Hello world\n");
return 0;
}

OP: You idiot, my interview question required no semicolons and your
program has two semicolons!

Keith-the-smart: The OP's question wasn't clear, but, upon a short
reflection, it became clear to me that he wanted a solution with no
semicolons. Probably because I know other languages where such a
solution doesn't require any semicolons.


If this analogy is broken, please explain why.

Dan
 
K

Keith Thompson

If you have anything to say, say it here, the discussion is still topical.
Whoever lost interest has already killfiled the thread.

No, the discussion is not topical. (I've added an '[OT]' tag to the
subject header.)

Dan, in the quoted paragraph above, the phrase "even when the intent
is perfectly clear" was not a reference to the original article that
started this thread. It was a reference to something I wrote a few
articles upthread, which you insisted on misinterpreting. I no longer
remember, or care, exactly what it was.

I could have clarified that point, but given the history of
discussions in which you and I have participated, I assumed it would
only have led to further confusion. I assumed that if you cared, you
would contact me by e-mail as I suggested, or that if you didn't care
you would let the matter drop. My offer to take this to e-mail still
stands; if it's that important to you, I'll go back through the
archives and try to straighten out any misunderstandings. But I will
not do so in this newsgroup. I believe that every question in this
thread that's of any possible relevance to C has already been
answered.
 
D

Dan Pop

In said:
[email protected] (Dan Pop) said:
If you have anything to say, say it here, the discussion is still topical.
Whoever lost interest has already killfiled the thread.

No, the discussion is not topical. (I've added an '[OT]' tag to the
subject header.)

Dan, in the quoted paragraph above, the phrase "even when the intent
is perfectly clear" was not a reference to the original article that
started this thread. It was a reference to something I wrote a few
articles upthread, which you insisted on misinterpreting. I no longer
remember, or care, exactly what it was.

So, you're completely incoherent.

I objected to your claim that the OP's intent could be derived from the
original question, even if it was not very clearly formulated. I claim
that the original question was clearly formulated and did NOT reflect the
OP intent. See also my analogy, that you removed in your reply.

If you maintain your claim, please justify it, rather than talking
about anything else in a desperate attempt to muddle the issue, as
you did with your "perfectly clear intent" above. We're [OT] now,
so you have no reason to hide behind false topicality scruples.

Dan
 
K

Kenny McCormack

Keith Thompson said:
I think most of the regulars here have either stopped reading Dan
Pop's postings or have learned to apply a mental "Dan Pop filter",
reading for technical content (which is usually very good) and
ignoring the abuse.

I may or may not qualify as a regular, but I read this NG with a "technical
content" filter - i.e., it filters out any extraneous technical content.
I read this NG for the abuse (it is so much fun) - and I'd imagine that is
true for most of the regulars. Surely, we all know about as much C as we
need to, so there's not much point in reading this in the hopes of
learning. Reading for abuse is so much more entertaining.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top