public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ static constructors.
@ 1998-05-14 17:57 PÃ¥l-Kristian Engstad
  0 siblings, 0 replies; only message in thread
From: PÃ¥l-Kristian Engstad @ 1998-05-14 17:57 UTC (permalink / raw)
  To: egcs

Hi!

Given this code snippet:

struct jim {
    jim(int x) : m(x) {}
    int m;
};

struct bob {  
    int m; 
};

static jim a(1);
static bob b = { 2 };

We will find that when constructing a, a space and time overhead
is incurred. Compiling with:

# g++ -fno-rtti -fno-exceptions -S -O3 constr.cc -o constr.s

gives:

	.file	"constr.cc"
/ GNU C++ version 2.7-B19 (i386-cygwin32) compiled by GNU C version
2.7-97r2aBeta.
/ options passed:  -O3 -fno-rtti -fno-exceptions
/ options enabled:  -fdefer-pop -fcse-follow-jumps -fcse-skip-blocks
/ -fexpensive-optimizations -fthread-jumps -fstrength-reduce -fpeephole
/ -fforce-mem -ffunction-cse -finline-functions -finline
/ -fkeep-static-consts -fcaller-saves -fpcc-struct-return -fgcse
/ -frerun-cse-after-loop -fschedule-insns2 -fcommon -fverbose-asm
/ -fgnu-linker -m80387 -mhard-float -mno-soft-float -mieee-fp
/ -mfp-ret-in-387 -mschedule-prologue -mstack-arg-probe -mcpu=i386
/ -march=pentium

gcc2_compiled.:
___gnu_compiled_cplusplus:
.32data
	.align 4
_b:
	.long 2
.lcomm _a,4
	.section .ctor
	.long	__GLOBAL_$I$constr.cc
.text
	.align 4
.globl __GLOBAL_$I$constr.cc
__GLOBAL_$I$constr.cc:
	pushl %ebp
	movl %esp,%ebp
	movl $1,_a
	leave
	ret

As you can see, the global constructor is not needed, yet the
compiler generates code to set a memory variable to 1.

Is anyone working on optimizing this and if not, where can I 
start?

PKE.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-05-14 17:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-14 17:57 C++ static constructors PÃ¥l-Kristian Engstad

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).