0

I have two C projects prepared under Visual Studio 2015. First project is simply a static library project whereas the second one is a console application which uses the static library file generated by the first project.

I checked the static library file with DUMPBIN tool in Windows and saw that there are many variables and functions exposed to outside which is very bad for the encapsulation issues.

My question is how can I be sure that I don't expose the functions which are supposed to be private. Do I need to check every time with that tool? My question is also covering the variables. All my static global variables are also exposed to outside. How can I force them to be private?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
sanchop22
  • 2,729
  • 12
  • 43
  • 66
  • Names with internal linkage should not be available to the outside by definition. If your library consists of multiple compilation units, just don't provide the internal declarations. – too honest for this site Apr 04 '17 at 14:46

1 Answers1

1

I don't think that presence in dumpbin output can be considered an "exposing". All your static global variables require some space allocation and probably an initialization at runtime. So it's only natural for them to be present in dumpbin output. Also if you are compiling with link-time code generation then everything is actually "exposed".

dodo951
  • 438
  • 4
  • 8
  • Ah, very useful information. So how can I understand which functions are exposed and which aren't? – sanchop22 Apr 04 '17 at 14:20
  • 2
    The proper way to provide a "public interface" in C is to write a header file that contains declarations for all publicly available stuff and hope that users of this header file won't try to go deeper and hook up some internal stuff (even by accident). For example if you have a non-static global variable int foo then someone may actually redeclare it in his own ".c" file as extern int foo and change. And same goes for functions. So whenever possible internal stuff should be declared as static because everything else is accessible from outside. – dodo951 Apr 04 '17 at 14:37