From mboxrd@z Thu Jan 1 00:00:00 1970 From: k_satoda@f2.dion.ne.jp To: gcc-gnats@gcc.gnu.org Subject: optimization/4131: Why the C++ compiler don't place a const class object to ".rodata" section? Date: Sun, 26 Aug 2001 09:46:00 -0000 Message-id: <20010826163655.31142.qmail@sourceware.cygnus.com> X-SW-Source: 2001-08/msg00669.html List-Id: >Number: 4131 >Category: optimization >Synopsis: Why the C++ compiler don't place a const class object to ".rodata" section? >Confidential: no >Severity: non-critical >Priority: medium >Responsible: unassigned >State: open >Class: change-request >Submitter-Id: net >Arrival-Date: Sun Aug 26 09:46:01 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Zutoshi >Release: unknown-2.9 >Organization: >Environment: various >Description: I want to use a 'fixed-pointed-value' as a replacement of 'floating-point-value'. But the const instance of my class never be placed to ".rodata" section. They seem to need ".ctors" , however the constructing code has only a constant instructions to store a certain value. I think it dosen't need any codes , and needs only few bytes of ".rodata" section. I tried same test on some compilers , but no one generate the codes I want. These can be a headache on machines that have little RAM. Please excuse my poor english typing.(I am a Japanese.) >How-To-Repeat: // compile the following with maximam optimization. class T { int raw; public: enum { BASE = (1<< 8) }; template T(value_type opr) : raw(static_cast(opr * BASE)) {} template operator value_type() const { return static_cast(raw) / BASE; } }; const T t1 = 1.0; const int i1 = static_cast(1.0 * T::BASE); int main(void) { return i1 ^ static_cast(t1); } >Fix: >Release-Note: >Audit-Trail: >Unformatted: