How can I perform pre-main initialization in C/C++ with avr-gcc?

后端 未结 9 2007
名媛妹妹
名媛妹妹 2020-12-28 09:21

In order to ensure that some initialization code runs before main (using Arduino/avr-gcc) I have code such as the following:

class Init {
public         


        
9条回答
  •  死守一世寂寞
    2020-12-28 10:22

    You can use GCC's constructor attribute to ensure that it gets called before main():

    void Init(void) __attribute__((constructor));
    void Init(void) { /* code */ }  // This will always run before main()
    

提交回复
热议问题