Use of #pragma in C

前端 未结 10 1758
囚心锁ツ
囚心锁ツ 2020-11-27 09:32

What are some uses of #pragma in C, with examples?

10条回答
  •  感情败类
    2020-11-27 10:08

    #pragma startup is a directive which is used to call a function before the main function and to call another function after the main function, e.g.

    #pragma startup func1
    #pragma exit func2
    

    Here, func1 runs before main and func2 runs afterwards.

    NOTE: This code works only in Turbo-C compiler. To achieve this functionality in GCC, you can declare func1 and func2 like this:

    void __attribute__((constructor)) func1();
    void __attribute__((destructor)) func2();
    

提交回复
热议问题