The appeded code does not compile without errors:
(Verified on avr-gcc (gcc version 4.2.2)
$ avr-gcc -Wall c++_trial_1.cpp
c++_trial_1.cpp:29: error: uninitialized const 'sM'
Using Visual Studio 2005 Express the same code compiles on the highest
warninglevel without warnings or errors.
#include
unsigned char PORTB;
unsigned char PORTC;
class port_b
{
protected:
inline void setPB0( void ) { PORTB |= (unsigned char) (1<<0);};
inline void resetPB0( void ) { PORTB &= (unsigned char) ~(1<<0);};
};
class port_c
{
protected:
inline void setPC0( void ) { PORTC |= (unsigned char) (1<<0);};
inline void resetPC0( void ) { PORTC &= (unsigned char) ~(1<<0);};
} ;
class signalManager
: protected port_b,
protected port_c
{
public:
inline void alarmLedOn( void ) {port_b::resetPB0();};
inline void alarmLedOff( void ) {port_b::setPB0();};
} const sM ;
int main( void )
{
printf("Port B %d\n", PORTB);
((signalManager&)sM).alarmLedOff();
printf("Port B %d\n", PORTB);
((signalManager&) sM).alarmLedOn();
printf("Port B %d\n", PORTB);
return 0;
}
--
Summary: Classes without attributes declared as const need
initializer.
Product: gcc
Version: 4.2.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: olof dot tangrot at telia dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34811