Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 2
    @Derrick Agree, int main is a proper thing, but gcc and other compilers compile this to a correctly running programs since 1990's. Explained pretty well here: eskimo.com/~scs/readings/voidmain.960823.html - it's basically a "feature", I take it like that. Commented Nov 18, 2010 at 16:32
  • 2
    @icyrock.com: All very true (regarding void main() in C), but when posting publicly it is probably as well to avoid the debate altogether by using int main() lest it distract from teh main point. Commented Nov 18, 2010 at 17:08
  • 34
    There is a huge flaw in this. You cannot safely use printf within the content of a signal handler. It's a violation of asynchronous signal safety. This is because printf is not reentrant. What happens if the program was in the middle of using printf when Ctrl-C was pressed, and your signal handler starts using it at the same time? Hint: It will likely break. write and fwrite are same to use in this context. Commented Nov 18, 2010 at 19:07
  • 2
    @icyrock.com: Doing anything complicated in a signal handler is going to cause headaches. Especially using the io system. Commented Nov 18, 2010 at 19:50
  • 2
    @stacker Thanks - I think it's worth it at the end. If somebody stumbles across this code in the future, better to have it right as much as possible, regardless of the topic of the question. Commented Nov 18, 2010 at 23:10