::?

This topic is 4617 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

This thread actually has a content specific topic, believe it or not. Anyway, I'm skimming over a section of code my boss wrote to model part of my program after, and I see he's doing things like this: ::glMatrixMode(GL_MODELVIEW); ::glLoadIdentity(); I've never seen syntax such as this before. What's up with the preceding scope resolution operator there? Are these function calls of abitrary scope or something? They don't belong to any class that I'm aware of, they're just simple calls to functions in the gl library. I could ask my boss, but I figure if that's something every novice programmer knows and I've somehow missed it these last 7 years, I'd rather lose face in front of you guys (my tender, loving, gamedevers) than my boss. So what does it mean and should I already know this?

Share on other sites
just means global scope [smile] aka the unnamed namespace.

Share on other sites
They are functions with global scope... there's no reason to have the scope resolution operator there except to indicate the fact that they do have global scope (and possibly to clear up any resolution conflicts with names in included namespaces)

Share on other sites
:: is simply the global namespace, ive seen it done a few times, just a coding style really.

Share on other sites
Ohhh. So if he were to declare member functions in his class of the same name, he'd be safe when making these calls? In other words, if his class were named myClass, and a myClass::glLoadIdentity() existed, calling ::glLoadIdentity() would call the one out of the gl library, rather than the one he's defined?

Share on other sites
Quote:
 Original post by CyberSlag5kOhhh. So if he were to declare member functions in his class of the same name, he'd be safe when making these calls?

Yes, but why he would declare functions with the exact same name as the OGL function...

Share on other sites
cos its his boss, and they do sick and twisted things....

Share on other sites
Quote:
Original post by jperalta
Quote:
 Original post by CyberSlag5kOhhh. So if he were to declare member functions in his class of the same name, he'd be safe when making these calls?

Yes, but why he would declare functions with the exact same name as the OGL function...

Heh, well of course he wouldn't. It was just a pertinent example.

Quote:
 cos its his boss, and they do sick and twisted things....

A very valid point [grin]

Thanks for the responses, everyone!

Share on other sites
Quote:
 Original post by paulecoyotejust means global scope [smile] aka the unnamed namespace.

The global namespace and unnamed namespaces are quite different beasts.

CyberSlag5k - this should make things clear:

int foo() { return 42; }namespace bar{   int foo() { return 66; }   int bar() { return foo() + ::foo(); }}

It's a bit like absolute and relative path for file names.

Share on other sites
Actually, that is done for the most part on laziness. Try it some time, with Visual C++'s intellisense, you can just do ::, then have the global names space, to which you can start typing the functions name, then hit enter to auto-complete it [smile] I do that all the time, but usually take out the :: when I am done.

Share on other sites
Quote:
 Original post by Drew_BentonActually, that is done for the most part on laziness. Try it some time, with Visual C++'s intellisense, you can just do ::, then have the global names space, to which you can start typing the functions name, then hit enter to auto-complete it [smile] I do that all the time, but usually take out the :: when I am done.

yeah i think you've got the exact reason there, bosses are lazy, hehehe

Share on other sites
Quote:
Original post by Fruny
Quote:
 Original post by paulecoyotejust means global scope [smile] aka the unnamed namespace.

The global namespace and unnamed namespaces are quite different beasts.

CyberSlag5k - this should make things clear:

int foo() { return 42; }namespace bar{   int foo() { return 66; }   int bar() { return foo() + ::foo(); }}

It's a bit like absolute and relative path for file names.

Quite clear. Thank you.

Quote:
 Original post by Drew_BentonActually, that is done for the most part on laziness. Try it some time, with Visual C++'s intellisense, you can just do ::, then have the global names space, to which you can start typing the functions name, then hit enter to auto-complete it I do that all the time, but usually take out the :: when I am done.

Ok, that is just awsome. That'll come in handy as I can never remember stuff like whether it's GL_MODELVIEW or GL_MODEL_VIEW. You have just saved me untold numbers of recompiles, Drew.

Share on other sites
Quote:
Original post by Structure
Quote:
 Original post by Drew_BentonActually, that is done for the most part on laziness. Try it some time, with Visual C++'s intellisense, you can just do ::, then have the global names space, to which you can start typing the functions name, then hit enter to auto-complete it [smile] I do that all the time, but usually take out the :: when I am done.

yeah i think you've got the exact reason there, bosses are lazy, hehehe

I'm not sure I'd call him lazy, but the man doesn't use the keyboard for ANYTHING. If it's somewehre in the code already, he'll hunt it down, highlight it with his mouse, right-click>>copy, go to where he wants it, right-click>>paste. I think what drives me the most crazy is the right-clicking. I usually just want to scream "Just hit CTRL+C!" or type the damn thing. It'd save so much freaking time.

Thus far, I have avoided such an outburst, fortunately [grin]

Share on other sites
Quote:
 Original post by CyberSlag5kIf it's somewehre in the code already, he'll hunt it down, highlight it with his mouse, right-click>>copy, go to where he wants it, right-click>>paste.

XWindow's Copy-On-Highlight + Paste-On-Middle-Click is highly addictive. (if anybody knows how to get that behaviour in Windows, I'm interested to hear about it).

Share on other sites
Quote:
Original post by Fruny
Quote:
 Original post by CyberSlag5kIf it's somewehre in the code already, he'll hunt it down, highlight it with his mouse, right-click>>copy, go to where he wants it, right-click>>paste.

XWindow's Copy-On-Highlight + Paste-On-Middle-Click is highly addictive. (if anybody knows how to get that behaviour in Windows, I'm interested to hear about it).

I don't think it's possible as a system-wide setting, but I know putty (the terminal program) does copy-on-highlight + paste-on-right-click

Share on other sites
Quote:
Original post by Fruny
Quote:
 Original post by paulecoyotejust means global scope [smile] aka the unnamed namespace.

The global namespace and unnamed namespaces are quite different beasts.

Yeah sorry... poor choice of words. unnamed namespaces are created with a unique name provided by the compiler.

clicky

Share on other sites
I prefix my gl calls with ::gl - it really emphasizes that you are making a global GL call and not deferring to some other routine.

I have a gl namespace that I have overloads in to make the correct ::gl calls for my primatives:

namespace gl{   inline void color(const mkh::graphics::color3f& c)   {      ::glColor(c.r, c.b, c.g);      MKH_GLCHECK;   }}//ns glcolor3f blue(0.0f,0.0f,1.0f);gl::color(blue);