Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22235

How to run a function before constructors from global variables

$
0
0

I have a ncurses program in c++ with global variables, which one containing the WINDOW*.

The problem is that I don't want to init every routines from ncurses in this constructor. I do want to init my ncurses things before everything else.

Here is my constructor :

 37 Window_c::Window_c()
 38 {
 41     // Create the window and check for errors
 42     if ((m_Window = newwin(0, 0, 0, 0)) == NULL) {
 43     ┊   fprintf(stderr, "[ERROR] - Unable to open the Window\n");
 44     ┊   exit(EXIT_FAILURE);
 45     }
 46 }

and here is my supposed main :

 33 __attribute__((constructor)) void CursesBeginRoutine(void)   
 34 {    
 35     initscr();   
 36     cbreak();        
 37     noecho();            
 38     keypad(stdscr, TRUE);   
 39 }
 40 
 41 int main(int argc __attribute__((unused)), char const *const argv[] __attribute__((unu|
 42 {
 43     MainLoop();
 44     return 0;
 45 }
 46                                                                                        
 47 __attribute__((destructor)) void CursesEndRoutine(void)
 48 {
 49     endwin();
 50 }

Sadly, it isn't working since gcc's attributes are called after constructors which is logic.

How can I do those things ?


Viewing all articles
Browse latest Browse all 22235

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>