Purpose of while(1); statement in C

前端 未结 12 1629
终归单人心
终归单人心 2020-12-08 00:53

What purpose does while(1); serve ? I am aware while(1) (no semicolon) loops infinitely and is similar to a spinlock situation. However I do not

12条回答
  •  旧巷少年郎
    2020-12-08 01:24

    This may be used to wait for Interrupt. Basically you initialize all things you need and start waiting for some thing to occur. After that some specific function is called and executed, after that it goes back to waiting state.

    That thing could be button pressed, mouse click/move, data received and etc.

    What is more I would say, similar stuff is really often used by UI frameworks. While it waits for signals about user actions.

提交回复
热议问题