c++ - Does C style casting adds assembly (code) or is it only for the compiler to understand the situation? -
class { public: *geta(void) { return a; } protected: *a; }; class b : public { public: b *getb(void) { return (b*)a; } };
in class assume compiler (ideally) optimize , inline getter no different code accessing variable directly ?
in class b variable cast b. purely compiler or involve code ? assembly instructions same function in b ?
most casts not insert assembler instructions, however, there exceptions:
expanding casts on signed integers: cast inserts sign extension instruction preserve value of negative values.
casts , floating point types: these casts perform full conversion, not reinterprete bits. consequently, computer has something.
pointer casts multiple inheritance. while first base first member in object, second base can't be. so, casting
derived*
secondbase*
adjust pointer, adding addition instruction code.
Comments
Post a Comment