I’m parsing some structures for a game. I know most things about the structures, but there are various things I don’t know, nor do I really care about them. But I need them in my parsing so things line up. For example:
template <unsigned int Size>
class unknown
{
BYTE data[Size];
};
struct s_object
{
int stuff;
unknown<100> unk1;
int otherstuff;
unknown<200> unk2;
};
This is a contrived example but it shows what I’m trying to do. I don’t like having to name members unk1 and then unk2. Ideally I’d like to do this
struct s_object
{
int stuff;
unknown<100>;
int otherstuff;
unknown<200>;
};
But of course that doesn’t work. Is there a way for the compiler to either generate a random name, use no name, or maybe just treat it as padding?
You can use the
__COUNTER__macro (but will need some preprocessor trickery). It is implemented by GCC, Visual C++ and probably others.You can then define a macro named, for example
_that expands to something like_unused_15,_unused_16and so on upon use. With it your code will become:The trickery being, i.e.