a few random questions

Started by
5 comments, last by TheAdmiral 17 years, 5 months ago
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.
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:: prefixusing mynamespace::SomeClass;int main(){   SomeClass someInstace;}// or// all symbols in mynamespace are available without //specifing the mynamespace:: prefixusing namespace mynamespace; int main(){   SomeClass someInstace;}
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?
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.
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.
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.
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
Ring3 Circus - Diary of a programmer, journal of a hacker.

This topic is closed to new replies.

Advertisement