papermario icon indicating copy to clipboard operation
papermario copied to clipboard

Move everything out of functions.h/variables.h

Open bates64 opened this issue 4 years ago • 2 comments

functions.h and variables.h have always been a temporary measure to make it quicker to match stuff. They define a ton of random functions and variables that should really be declared elsewhere.

The ~~not-yet-enabled~~ warnings -Wimplicit -Wredundant-decls described in #366 are relevant here too, as they will enforce good use of header files.

Additionally, we should move all declarations out of .c files and into .h files.


Steps to migrate functions from functions.h:

  1. Pick a C file with nonstatic functions you'd like to make a header for
  2. Create a header file (.h) next to the C file with an include guard
  3. Add an extern declaration for global variables defined in the C file (usually marked with g at the start of the variable name)
  4. Add a declaration for every non-static function in the C file
  5. Remove declarations from functions.h and variables.h
  6. Add a #include "myfoo.h" to every file that uses variables or functions declared in your header

Include guard example

#ifndef _MYFOO_H_
#define _MYFOO_H_

// ...

#endif

bates64 avatar Aug 18 '21 13:08 bates64

If we reenable clang-tidy we should be able to automatically shout about declarations that aren't in headers

bates64 avatar Nov 01 '22 14:11 bates64