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?
Regards,
Mohan.
Nov 14 '05
44 2045
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.
>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. mo************@ msn.com (Mohanasundaram ) writes: 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.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
In <ln************ @nuthaus.mib.or g> Keith Thompson <ks***@mib.or g> writes: Da*****@cern.c h (Dan Pop) writes: In <9b************ *************@p osting.google.c om> mo************@ msn.com (Mohanasundaram ) writes: >Hi Dan, > > This was an interview question. It is not a homework question. I >just wanted to know whether it is possible to do that like what we do >in C++. We use :: operator in C++ to access the global variable. I >wanted to know is there any language support in C to do this. If you >know please share the answer. If not please ...... Are you a patent idiot or what? I have already provided the answer. Or are you unable to read standard C code?
There was no mention of the C++ :: operator in your initial question, was it?
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 "clarificat ion" 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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de Da*****@cern.ch (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. 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 "clarificat ion" 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.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
On 2 Jul 2004 01:22:45 -0700, in comp.lang.c , mo************@ msn.com
(Mohanasundaram ) wrote: 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
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- mo************@ msn.com (Mohanasundaram ) wrote in message news:<9b******* *************** ****@posting.go ogle.com>... 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>
In <ln************ @nuthaus.mib.or g> Keith Thompson <ks***@mib.or g> writes: Da*****@cern.c h (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. The OP's "clarificat ion" 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.
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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
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.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
> 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tim Tyler |
last post by:
PHP puts most of its functions into a big flat global namespace.
That leads to short function names - but creates a namespace
minefield for programmers.
Lots of the functions are legacies from the days before PHP
got object-oriented features.
For instance we currently have:
|
by: Fernando Rodríguez |
last post by:
Hi,
I haven't used Python in quite some time, and I'm bit puzzled by this:
counter = 0
class Blah(object):
def run(self):
counter += 1
|
by: C Gillespie |
last post by:
Dear All,
I have 2 arrays
var A1 = new Array();
A1 ="Y2";
var B1 = new Array();
B1 ="Y1";
B1 ="sink";
|
by: Capstar |
last post by:
Hi,
I am working on an application, which will run embedded without an OS.
The app is build up out of a couple of well defined parts. At first I
wanted to keep those parts seperated and use opaque data types to
transfer information in between them.
At some stage I was stuck and needed to make a variable global, and I
also needed to make the struct declaration public to some other parts.
Looking through the code I found out that lots...
|
by: Shilpa |
last post by:
Hi,
I just wanted to know whether we can access global variable within a
local block , where both variables are having same name.
For ex:
int temp=5 ;
{
int temp=10;
| |
by: Ed Jensen |
last post by:
I'm having a vexing problem with global variables in Python. Please
consider the following Python code:
#! /usr/bin/env python
def tiny():
bar =
for tmp in foo:
bar.append(tmp)
foo = bar
|
by: weaknessforcats |
last post by:
C++: The Case Against Global Variables
Summary
This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have called it polluting the global namespace. This article explores what happens when the global namespace becomes polluted and how to avoid this condition.
The opinions expressed in this article are those of the author alone although many have...
|
by: istillshine |
last post by:
When I control if I print messages, I usually use a global variable
"int silent". When I set "-silent" flag in my command line
parameters, I set silent = 1 in my main.c.
I have many functions that may print some messages.
foo(...)
{
if (!silent)
|
by: Dheeraj Joshi |
last post by:
Hi, I was wondering is there any technique available, so we can access the global variable inside a function if we have a local variable inside the function with the same name as global variable.
Example
#include<something.h>
int countVal = 100;
/*
Some stuff
*/
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |