0

I have a scenario.c file that defines the some functions like below:

Static Functions:

scenario_config(), scenario_start(), scenario_stop(), scenario_close()

Structure (only thing) Visible to Parent Src/Header files:

struct scenario_struct = {.config = scenario_config, .start = scenario_start, .stop = scenario_stop, .close = scenario_close}

Also, there is a scenario.h header file that declares a ton of #defines and such that is included in the parent header file too.

Now coming to my question: There is a set of static helper functions and static constants and #defines in this scenario.c file that I want to put in a different file, to reduce clutter. I would be making them non-static to do so. But, they are only used in this file, so putting them in scenario.h makes it visible to its parent as well. I thought of a second header, but dont think I can put the static constants in there. What is the best way to do this?

Pablo
  • 13,271
  • 4
  • 39
  • 59
  • You cannot put static functions into a different .c file – Jabberwocky Feb 21 '18 at 20:21
  • maybe you could put your static functions in a separate file like `static_functions.c` file, then `#include "static_functions.c"` in `scenario.c`,, but I don't know I've never tried anything like that. – yano Feb 21 '18 at 20:25
  • 1
    If the helper static functions and static constants are meant to be used only in the file 'scenerio.c' file, then what is the need to put them into a different file? – hafeez Feb 21 '18 at 20:25
  • Okay, I was planning on making the functions and constants non static if I move them to a different file. The main intention of doing this was to reduce clutter as the helper functions grew a lot and made it difficult to just go through the basic static functions. I would like some tips on whether this is a good idea, or a terribly bad one. It makes the code easier to read, but is another layer of abstraction. – Arjun Augustine Feb 21 '18 at 20:34
  • 1
    Are you confusing "file" with "compilation unit"? You can `#include` another C file, it is part of the same unit. It need not appear in the makefile. – Weather Vane Feb 21 '18 at 20:44

1 Answers1

0

As mentioned by Michael in the comments, you can't move the static functions into another file.

Also see: How to call the static function from another c file?

tehp
  • 5,018
  • 1
  • 24
  • 31