Andes Workshop
http://forum.andestech.com/

Global object constructor is not called
http://forum.andestech.com/viewtopic.php?f=6&t=828
Page 1 of 1

Author:  banyh [ Thu Apr 17, 2014 3:17 pm ]
Post subject:  Global object constructor is not called

Code:
class Test {
public:
   int id;
   Test (int newid) : id(newid) {}
};
Test Test1(123);

int main ()
{
   printf ("%d\n", Test1.id);
}

在dev-c++執行時,可以正常的印出123。
但是用Andesight,會印出0 (因為Test1放在bss section),沒有呼叫constructor。

這個問題的目的,是希望能建立global object with constant member。例如:
Code:
class Test {
public:
   const int id;
   Test (int newid) : id(newid) {}
};
Test Test1(1), Test2(2), Test3(3);

Author:  jerry [ Mon Apr 21, 2014 12:05 pm ]
Post subject:  Re: Global object constructor is not called

Hi banyh,

http://stackoverflow.com/questions/22130402/can-gcc-optimize-methods-of-a-class-with-compile-time-constant-variables

this question is the same at URL,

GCC 4.7 will support the "constexpr " , but andes toolchain is based on GCC 4.4.4.

The Andes toolchain will be update GCC version at the future.

Page 1 of 1 All times are UTC + 8 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/