Sign in to follow this  

Recommended Posts

CyberSlag5k    514
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 this post


Link to post
Share on other sites
jperalta    356
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 this post


Link to post
Share on other sites
CyberSlag5k    514
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 this post


Link to post
Share on other sites
jperalta    356
Quote:
Original post by CyberSlag5k
Ohhh. 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 this post


Link to post
Share on other sites
CyberSlag5k    514
Quote:
Original post by jperalta
Quote:
Original post by CyberSlag5k
Ohhh. 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 this post


Link to post
Share on other sites
Fruny    1658
Quote:
Original post by paulecoyote
just 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 this post


Link to post
Share on other sites
Drew_Benton    1861
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 this post


Link to post
Share on other sites
Structure    240
Quote:
Original post by Drew_Benton
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.



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

Share this post


Link to post
Share on other sites
CyberSlag5k    514
Quote:
Original post by Fruny
Quote:
Original post by paulecoyote
just 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_Benton
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 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 this post


Link to post
Share on other sites
CyberSlag5k    514
Quote:
Original post by Structure
Quote:
Original post by Drew_Benton
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.



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 this post


Link to post
Share on other sites
Fruny    1658
Quote:
Original post by CyberSlag5k
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.


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 this post


Link to post
Share on other sites
jperalta    356
Quote:
Original post by Fruny
Quote:
Original post by CyberSlag5k
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.


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 this post


Link to post
Share on other sites
paulecoyote    1065
Quote:
Original post by Fruny
Quote:
Original post by paulecoyote
just 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 this post


Link to post
Share on other sites
Shannon Barber    1681
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 gl

color3f blue(0.0f,0.0f,1.0f);
gl::color(blue);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this