Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > scope resolution operator???????

Reply
Thread Tools

scope resolution operator???????

 
 
sushant
Guest
Posts: n/a
 
      01-07-2005
hi ,

can we use scope resolution operator (: in C???

sushant
 
Reply With Quote
 
 
 
 
Erik de Castro Lopo
Guest
Posts: n/a
 
      01-07-2005
sushant wrote:
>
> hi ,
>
> can we use scope resolution operator (: in C???


No, that is a c++ specific kludge.

Erik

--
+-----------------------------------------------------------+
Erik de Castro Lopo http://www.velocityreviews.com/forums/(E-Mail Removed) (Yes it's valid)
+-----------------------------------------------------------+
"To me C++ seems to be a language that has sacrificed orthogonality
and elegance for random expediency." -- Meilir Page-Jones
 
Reply With Quote
 
 
 
 
Derrick Coetzee
Guest
Posts: n/a
 
      01-07-2005
sushant wrote:
> can we use scope resolution operator (: in C???


The only reason to do so would be to access some member of a namespace
or class - neither of which C has. What application did you have in mind?
--
Derrick Coetzee
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-07-2005
(E-Mail Removed) (sushant) writes:
> can we use scope resolution operator (: in C???


No.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <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.
 
Reply With Quote
 
infobahn
Guest
Posts: n/a
 
      01-07-2005
sushant wrote:
>
> hi ,
>
> can we use scope resolution operator (: in C???


No, C doesn't have that operator.
 
Reply With Quote
 
thesushant@rediffmail.com
Guest
Posts: n/a
 
      01-07-2005
i want to access the value of global variable inside the main function
and inside the main func the var with the same name is available..for
eg.

int x=20;

main()
{
int x=10;
printf("%d",x);

}
i want the o/p to be 20.. how can v achieve that?
Derrick Coetzee wrote:
> sushant wrote:
> > can we use scope resolution operator (: in C???

>
> The only reason to do so would be to access some member of a

namespace
> or class - neither of which C has. What application did you have in

mind?
> --
> Derrick Coetzee


 
Reply With Quote
 
Andrey Tarasevich
Guest
Posts: n/a
 
      01-07-2005
Derrick Coetzee wrote:
>> can we use scope resolution operator (: in C???

>
> The only reason to do so would be to access some member of a namespace
> or class - neither of which C has.


It can also be used to access a hidden global name from a local scope.
Theoretically, for this very purpose '::' could be useful in C as well.

I'm not saying though that this is enough to justify the need for '::'
operator in C. It is not.

--
Best regards,
Andrey Tarasevich

 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      01-07-2005
(E-Mail Removed) writes:

> i want to access the value of global variable inside the main function
> and inside the main func the var with the same name is available..for
> eg.
>
> int x=20;
>
> main()
> {
> int x=10;
> printf("%d",x);
>
> }


main()
{
int x = 10;
{
extern int x;
printf ("%d", x);
}
...
}
--
"The expression isn't unclear *at all* and only an expert could actually
have doubts about it"
--Dan Pop
 
Reply With Quote
 
Taran
Guest
Posts: n/a
 
      01-07-2005
(E-Mail Removed) wrote:
> i want to access the value of global variable inside the main

function
> and inside the main func the var with the same name is available..for
> eg.
>
> int x=20;
>
> main()
> {
> int x=10;
> printf("%d",x);
>
> }
> i want the o/p to be 20.. how can v achieve that?

NO.

Whenever there's a name clash between a local and global variable the
local variable name and value is recognized.
AFAIK there's isn't any way to access global variable with name clashes
with a local vairable. I knew this so I haven't ever used same name in
local scope, my company's coding guidelines suggest we don't do that
, so I never tried accessing the global variable, so I'm not aware even
it exists.

HTH.
Regards,
Taran

 
Reply With Quote
 
Derrick Coetzee
Guest
Posts: n/a
 
      01-07-2005
(E-Mail Removed) wrote:
> i want to access the value of global variable inside the main function
> and inside the main func the var with the same name is available..


Ah, I didn't think of this. Another reply indicated one way of doing
this. However, this is purely academic, since if this situation ever
arose in practice you should rename one of your variables right away. In
short: don't ever give a global a name that might be reasonably used by
a local variable. If this results in large variable names, you can use
the #define/#undef trick:

int num_furry_bunny_suits = 2;

#define suits num_furry_bunny_suits
void foo(int i) {
suits += i;
return suits;
}
#undef suits

Cleaner but (sometimes) less efficient is a local pointer:

void foo(int i) {
int* suits = &num_furry_bunny_suits;
*suits += i;
return *suits;
}

--
Derrick Coetzee
I grant this newsgroup posting into the public domain. I disclaim all
express or implied warranty and all liability. I am not a professional.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Lexical scope vs. dynamic scope Xah Lee Java 0 02-26-2009 10:08 AM
CSPEC issue: lossing scope (or incorrect scope) in cspec subroutine. balldarrens@gmail.com Perl Misc 0 02-05-2009 08:42 PM
Scope - do I need two identical classes, each with different scope? ann Java 13 09-13-2005 03:07 AM
How do namespace scope and class scope differ? Steven T. Hatton C++ 9 07-19-2005 06:07 PM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM



Advertisments