[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Duplicated C++ constructor code
From: |
Greg Tunnock |
Subject: |
[avr-gcc-list] Duplicated C++ constructor code |
Date: |
Wed, 20 Nov 2002 00:16:25 +1100 (EST) |
Hi,
I'm using avr-gcc-3.3.2002.10.01 on FreeBSD to compile C++ code. The listing
file from avr-objdump show that the compile has duplicated the code for the
class constructors.
Here is a simple C++ source file that shows the problem:
#include <avr/io.h>
#if defined(__AVR_AT90S2313__)
#define LED1 PD4
#elif defined(__AVR_ATmega128__)
#define LED1 DD4
#endif
class Led1
{
public:
Led1();
void off();
void on();
private:
Led1(const Led1 &from); // Prevent copying.
Led1 &operator=(const Led1 &from); // Prevent assignment.
};
Led1::Led1()
{
sbi(DDRD, LED1);
}
void Led1::off()
{
sbi(PORTD, LED1);
}
void Led1::on()
{
cbi(PORTD, LED1);
}
int main()
{
Led1 led1;
for (;;)
{
led1.off();
led1.on();
}
}
And the sections of the listing that shows the duplicated constructor code
for Led1:
000000ca g F .text 00000004 Led1::Led1()
000000ce g F .text 00000004 Led1::Led1()
000000ca <Led1::Led1()>:
};
Led1::Led1()
{
sbi(DDRD, LED1);
ca: 8c 9a sbi 0x11, 4 ; 17
}
cc: 08 95 ret
000000ce <Led1::Led1()>:
ce: 8c 9a sbi 0x11, 4 ; 17
d0: 08 95 ret
The commands lines that the C++ source file is compiled with and the listing
file generated with are:
avr-g++ -g -Wall -O2 -mmcu=atmega128 -fno-exceptions -c -o main.o main.cc
avr-g++ -g -Wall -O2 -mmcu=atmega128 -Wl,-Map,main.map -o main.elf main.o
avr-objdump -h -S -C -D -w -a -t -f main.elf > main.lst
When stepping through code with avr-gdb on simulavr, only the second
constructor (000000ce) is called.
Is this a problem with avr-gcc? Or am I doing something silly? Or have I
miss understood some aspect of C++?
Cheers,
Greg Tunnock
avr-gcc-list at http://avr1.org
- [avr-gcc-list] Duplicated C++ constructor code,
Greg Tunnock <=