Calling some functions before main in C

后端 未结 4 1290
孤独总比滥情好
孤独总比滥情好 2020-12-06 07:15

I\'d like to do some stuffs before main function. I have multiple source files. In each file, there is some work that needs to be done before main.

4条回答
  •  旧巷少年郎
    2020-12-06 07:55

    (I know, this isn't a direct answer to the original question; it is, however, an answer for someone who's looking for a way to execute code before the contents of main)

    I've heard of a better idea - one, that's even portable and predictable in behavior. Do the stuff you want to do "before main" in the beginning of the main function (or call a function which does what you want in the beginning of main).

    If you control the code, there's (really!) no need for fragile and often unmaintainable hacks like the ones you have proposed (or introduced).

提交回复
热议问题