Tool/software: TI C/C++ Compiler
class Board { public: virtual ~Board(); Syslog* syslog() { return syslog_; }; protected: Board() : syslog_(NULL) {}; Syslog* syslog_; } class BoardImpl : public Board { public: BoardImpl(); }; BoardImpl::BoardImpl() : Board() { Board::syslog_ = Syslog::Init(); } void some_function() { BoardImpl board; Board *board_ptr = &board; Syslog* syslog_local = board_ptr->syslog(); // works fine syslog_local->Printf("blah"); // crashes with unaligned access board_ptr->syslog()->Printf("blah"); }
Can someone tell me why the above code crashes? We're using compiler 15.12.5, and we consistently see this crash happen on a TM4C if we use a function call that returns a pointer, then dereference it in this way. I suspect the compiler's not doing the right thing.