Jump to content
  • Advertisement
Sign in to follow this  
ELFanatic

a few random questions

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I see that address locations are always in the form 0xnumbers. is the 0x prefix simply reserved for addresses or does it encompass more than just addresses? can it ever be 1x or 2x? if not, why the 0 in front? Also, I know you can type using namespace [name] but is there a way you can stop using the namespace.

Share this post


Link to post
Share on other sites
Advertisement
Addresses are (usually) 32 bit numbers, just like ints usually are.

To make addresses appear differently than numbers they print them in a hex format, where 0x means the value following is in hex. Ig you are using c++ and want to make an integer have the value of a number in hex, you can use the same prefix:

int someMask = 0xff00;

Stop using the namespace? If you mean stop typing the namespace's name you can do this:

namespace mynamespace
{

class SomeClass
{
};

}


// The class SomeClass is available without
//specifing the mynamespace:: prefix
using mynamespace::SomeClass;

int main()
{
SomeClass someInstace;
}

// or
// all symbols in mynamespace are available without
//specifing the mynamespace:: prefix
using namespace mynamespace;

int main()
{
SomeClass someInstace;
}


Share this post


Link to post
Share on other sites
okay so it's for hex representation. So if I wanted to I could do something like this?

int hex = 0xAAFF5522;

And there will be no problem. Which would be incrediably helpful with colors.

yeah, an inverse to using namespace.

example:



int main()
{
using mynamespace std;
cout << "hi";
//then turn it off
cout << "hello"; //error //no longer using namespace std, need fully qualifying name.
}

Is this possible?

Share this post


Link to post
Share on other sites
Quote:
Original post by ELFanatic
yeah, an inverse to using namespace.

example:



int main()
{
using mynamespace std;
cout << "hi";
//then turn it off
cout << "hello"; //error //no longer using namespace std, need fully qualifying name.
}

Is this possible?

Removing an introduced namespace is not possible as far as I know. They are, however, limited by scope.

int main()
{
{
using mynamespace std;
cout << "hi";
}
//then turn it off
cout << "hello"; //error //no longer using namespace std, need fully qualifying name.
}

Last line is an error now, for the reason stated in the comment.

Share this post


Link to post
Share on other sites
oh sweet, I think I understanding the difference between your two examples, that's pretty cool. I didn't know you could do it down to the class, I thought it'd have to resolve to a namespace. so I could do using namespace std::cout and only cout wouldn't need the prefix other STL classes would. That's good to know.

Share this post


Link to post
Share on other sites
Quote:
Original post by Brother Bob
Quote:
Original post by ELFanatic
yeah, an inverse to using namespace.

example:



int main()
{
using mynamespace std;
cout << "hi";
//then turn it off
cout << "hello"; //error //no longer using namespace std, need fully qualifying name.
}

Is this possible?

Removing an introduced namespace is not possible as far as I know. They are, however, limited by scope.

int main()
{
{
using mynamespace std;
cout << "hi";
}
//then turn it off
cout << "hello"; //error //no longer using namespace std, need fully qualifying name.
}

Last line is an error now, for the reason stated in the comment.


sweet, that's a reasonable answer.

Share this post


Link to post
Share on other sites
For completeness:
Quote:
Original post by ELFanatic
okay so it's for hex representation. So if I wanted to I could do something like this?

int hex = 0xAAFF5522;

You surely can. Once a literal integer gets through the compilation phase, it will be stored in binary, no matter how you specified it. It's just that sometimes it's more convenient to work in hexadecimal; others in decimal.

The following lines of code are not just functionally equivalent but will compile to precisely the same thing:
int x = 16;
int x = 0x10;
Regards
Admiral

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!