How much memory is allocated for a single boolean value? Just a bit? Do they allocate a whole byte to keep a consistent pattern? Or does it vary across compilers?
A whole byte. It's not possible to allocate a single bit in any modern computer (that I know of, anyway).
However, some structures, such as std::vector, have specializations that make each bool element use only one bit.
The same way you would use a vector to store anything else.
Remember, though, that the computer cannot use less memory for any one object than a byte. You can pack multiple bit-booleans into a single byte... but that's all.
Specializing the vector class on bits was a mistake in the STL, alas.
Feel free to call me a fool, but hey, it's worth a shot.
A program I use called 'GameMaker' allows its variables to represent any value. Whether it be an int, a string, a char, or a pointer, you can use it. I know that you can use a void pointer for this, but I thought that this would be a nice little project. Even if it fails, it would be a nice learning experience.
Basically, my idea is to make a class where the objects could represent any value without the need for type casting. I was thinking of using malloc to allocate the necessary memory, but apparently the vector class should handle it for me. The only problem I could see with this would be handling pointers, since there isn't really any way to get around without the user having to use type casting in some way.
Although, after writing this, I feel like this would be pretty much a worthless project. I couldn't see much of a practical use for this even if it is successfully made.
I might be misunderstanding, but this sounds like the antithesis of C++ programming. C++ wants to be strongly typed; what you are doing is trying to completely eliminate C++'s typing system.
How exactly does a user use your type? What are it's API methods? What can a user do with this type?
Depending on your answer, perhaps boost::any would fit the bill.
Just because GameMaker's implemented in C++, it doesn't follow that GameMaker's variables should be strongly typed. It all depends on how they're used. If all you do is hold numbers and strings, if doesn't really matter how they're represented.
Keywords can be used to imply type when necessary, that's a fairly common convention.
The variables in GM can hold any values. An object, a number, text, a pointer, anything. But since a lot of things are done without the user ever even seeing it, I'm not entirely sure how it works.
I might be misunderstanding, but this sounds like the antithesis of C++ programming. C++ wants to be strongly typed; what you are doing is trying to completely eliminate C++'s typing system.
This library is meant to be used to allow people to move from GML (GM's language) to C++ easily and still be able to make games quickly. However, I've realized that if people can't even figure out how to declare variables, they probably won't get too far anyways.
I prefer strongly typed languages. If I want a user to pass a string, I don't want to have to do the checking myself and warn the user, I want them to get an error for being stupid.
That's another thing. Better to let the user know that they're using the wrong variable than to let them get away with it and have them think there's something wrong with the library.