This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

optimization/4131: Why the C++ compiler don't place a const class object to ".rodata" section?



>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<class value_type> T(value_type opr) : raw(static_cast<int>(opr * BASE)) {}
	template<class value_type> operator value_type() const { return static_cast<value_type>(raw) / BASE; }
};

const T t1 = 1.0;
const int i1 = static_cast<int>(1.0 * T::BASE);

int main(void)
{
	return i1 ^ static_cast<int>(t1);
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]