c++ instance coding fear resplendent idea?
at before employer, minute binary messages "over wire" computers. any summary customary header something like:
class header
{
int type;
int payloadlength;
};
all information consistent (header, immediately followed data). wanted load given pointer header. traditionally, competence contend something like:
char* header::getpayload()
{
relapse ((char*) &payloadlength) + sizeof(payloadlength);
}
or even:
char* header::getpayload()
{
relapse ((char*) this) + sizeof(header);
}
that seemed kind verbose, i came adult with:
char* header::getpayload()
{
relapse (char*) &this[1];
}
it seems rather unfortunate during first, presumably too rare -- nonetheless unequivocally compact.
there lot plead presumably resplendent an abomination.
so - crime opposing coding, good solution? have ever identical trade-off?
-update:
we try 0 sized array, nonetheless during time, compilers gave warnings.
we eventually went inhertited technique: summary derives header.
it works good practice, nonetheless priciple observant summary isa header - seems small awkward.
Comments
Post a Comment