Can I create C functions that are visible only to my class, which is split into several files?

Using a static function, I can limit the connection of my function with the file at hand, and this is ideal in many cases. But I have a class that is cumbersome, like a single file, but its break becomes more frustrating, because there are functions that I would like to keep 'private', but they are needed in everything.

+3
source share
3 answers

Upon request, my comment on OP as an answer:

There is no language support that I know about ... could you put all the support functions in a separate file c and only #import its header from the class implementation files? If they should not be C functions (for example, to pass as callbacks to the C APIs), I would redefine them as methods in the class and declare the private interface in a separate header - each implementation file would have to #import as a "public" header and "private".

+1
source

One part of the answer should be counter questions, for example:

  • Why is your class so large that you need to separate it?
  • Are you sure your class is so large that you need to separate it? (How big is "big"?)
  • Are you sure your class is abstracted correctly?
  • , , ? , .

, , - ; , .

, , ( , ) , : ? ( , , ?)

, 4 ( ) .

  • class.h
  • class.c
  • class1.c
  • class2.c

, class.h, - . ( ) , .

class1.c class2.c . , - . ; , , .

class.c - , . :

  • #include "class.h"
  • , .
  • #include "class1.c"
  • #include "class2.c"

, , , class.c.

makefile , class.o ; - , . (class1.c class2.c) , , C (Objective-C). , , , , . IDE, .

, , , . ; . , , .

+3

The prefix of their names with the output of the cryptographic RNG. Now you don’t have to worry about unintended name collisions. The problem is solved. You can hide renaming in preprocessor macros if you really like it.

+1
source

All Articles