8

I am currently working on a project with some old poorly documented code, and am trying to navigate my way through the various .h files that they have provided complete documentation on the use of all of the functions contained (the definitions are held in .lib and .dll files). One of the .h files has functions the are not only declared, but defined with either simple return statements or empty statements as such

class DLL ExampleLibraryClass {
public:
    int exampleGetValue() {return 0;}
    void exampleSetValue(Type val) {;}
    void exampleActionFxn() {;}
};

These would be functions that I expect to return current variable states or perform certain actions, which is why this puzzles me.

Additionally:

  • I have used Dependency Walker and found that each function does have a matching definition in a dll.

  • The Keyword DLL has been defined with

    #ifndef _PWSDLL_
    #   define _PWSDLL_
    #   define WINCALL  _stdcall
    #   ifdef _USRDLL
    #       define DLL  __declspec(dllexport)
    #   else
    #       define DLL  __declspec(dllimport)
    #   endif
    #endif
    

    _USRDLL is not defined and therefore DLL is defined as __declspec(dllimport)

My question revolves less about the apparent effect of the empty definitions (which do nothing I suppose, and have already been discussed on SO) and more about why the .h file has been written this way and how to utilize the file. Is this a common or known practice? Will the linker still look for definitions to the function in my linked libraries? Are there other pieces of code that I should look for for more clues? Or perhaps in the broadest sense, how should I respond to this?

Many thanks, and please let me know if you need more information to address this, I am unsure what exactly is important in this matter.

EDIT: Added forgotten return types in example code.

EDIT: Added note about DLL definition.

rtmh
  • 439
  • 3
  • 9
  • 3
    Are you sure the header is always consumed like this, in every compilation scenario? There might be some conditional compilation at work, which makes the class a "dummy class" in certain conditions. – KABoissonneault Jun 22 '16 at 14:50
  • 3
    The missing returns types concern me. That is not valid C++. – NathanOliver Jun 22 '16 at 14:53
  • 3
    This is not valid C++. – Lightness Races in Orbit Jun 22 '16 at 14:53
  • @juanchopanza `DLL` is probably a precompilation macro for compiler specific class attributes. The missing return types are probably a mistake, but we'll have to wait for OP's answer to know – KABoissonneault Jun 22 '16 at 14:54
  • @jaunchopanza and @NathanOliver and @Lightness My sincere apologies, I forgot the return types when rewriting the code as an example. Also, @juanchopanza Indeed, it is defined as `__declspec(dllimport)` in the standard conditional way. sorry I didn't include that before – rtmh Jun 22 '16 at 15:01
  • @rtmh Thanks, I wasn't worried about the `DLL`, but about the missing return types. – juanchopanza Jun 22 '16 at 15:04
  • The following link explains the DLL definition. http://stackoverflow.com/questions/8863193/what-does-declspecdllimport-really-mean – Jim Vargo Jun 22 '16 at 15:27
  • 1
    The public interface of a DLL is immutable if you don't control the apps that use the DLL. Stubbing functions that you no longer need keeps the DLL compatible with old client apps that are not getting recompiled. – Hans Passant Jun 22 '16 at 17:08
  • @HansPassant So that would suggest that the stubbed functions are not to be used? Somewhat like a 'depreciated' tag? – rtmh Jun 22 '16 at 17:41
  • 1
    Roughly, yes. Backwards binary compatibility is the larger goal here. Ideally this api is properly documented and when the revision was made that stubbed out the functions, it was updated by removing these functions. – Hans Passant Jun 22 '16 at 18:25
  • @HansPassant Thank you very much, I think I will move on to discern the version of my library and .h files which might illuminate the situation some more for me. I think, though, that this composes a significant answer for my question, if you would like to write it up as such, I would love to credit you. – rtmh Jun 22 '16 at 21:34

1 Answers1

0

One scenario where you put this code to some use would be to override the functions. These functions hold some default code and could be overridden later.

Shiro
  • 2,610
  • 2
  • 20
  • 36
  • Is it advisable then when using the .h file to comment out the dummy definitions to get at the library definitions instead? – rtmh Jun 22 '16 at 15:36
  • If they are implemented somewhere else then yes. Otherwise you would have to implement them yourself. – Shiro Jun 22 '16 at 16:15