当前位置:网站首页>Experience in writing C

Experience in writing C

2022-06-25 10:02:00 TowerOs

Show yourself

Coding problem

  1. Before any data is used, it is best to 0 initialization
  2. Reduce the use of macros , Unless it's for The purpose of global source code architecture , For example, according to Kconfig Configure the increase / decrease module ; Try to use global variables and inline Function to complete
  3. Don't have object-oriented thinking , Don't let object orientation spoil your mind
  4. header The file is equivalent to controlling the external closeness of the source code , treat as public private Just use keywords
  5. Use struct Structure , Coordinate functions to simulate object-oriented , If you really need object orientation
  6. Be sure to know who owns this memory , such as : The end of the thread returns the memory in its own stack as a result , It is very …silly

Process related

  1. Use... Firmly pthread_mutex_timelock Prevent permanent blockage , They can't be used pthread_mutex_clock
  2. Pay attention to a lot pthread Different implementation completion degree in different operating systems , such as return End thread Of pthread_clean_pop The program will not execute , Because it won't call pthread_exit

Solve the inapplicability of object-oriented to structural language

  1. fuck it
原网站

版权声明
本文为[TowerOs]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200547375100.html