Mark Whitis's Website Home Page Linux Book: Linux Programming Unleashed My Resume Genealogical Data Contact Info Security About

[HOME(Mark Whitis)] [Contact] [Resume] [Browser Friendly] [No Spam] [FEL] [DBD]

Avoiding DLL Hell

This page provides some notes on avoiding DLL hell when creating libraries. Changes to library API's often create a real mess for users.

Always initialize structures by copying from defaults

In the library:


   typedef struct {
      int x;
      int y;
      int z;
      char pad[16];
   } point_3d_t;
   point_3d_t point_3d_defaults = {
      0,0,0
   }

In the application program:


   point_3d_t point;
   point = point_3d_defaults;  // <--- always do this first
   point.x = 100;
   point.y = 200;
   point.z = 300;
   function_using_point(point);

Now consider what happens when we add a member "layer" to point_3d_t.

Use consistent naming conventions. A type ends in "_t", the defaults for that type ends in "_defaults", a pointer ends in "_p", etc.

Add padding

Add some padding as illustrated above. Reduce the padding when you add new members: char pad[16 - sizeof(int)]; Combined with the defaults, this can provide binary compatibilty even though the structure changes. Note, however, that with different sizes for int and different alignment rules on RISC CPUS there may be some more sophistication needed here.

Put versions on functions

Instead of function_using_point(), define function_using_point_v1(). When you change the parameters to the function in the future, change the name to function_using_point_v2() and define a short function_using_point_v1() that calls function_using_point_v2().

This file is maintained by Mark Whitis (whitis@freelabs.com).

Senior Engineer for hire
Software Development - Electronic Design - Embedded Systems - Device Drivers - System/Network Administration and Security - Motor Control, RobotCNC - Linux/Un*x - 25+ years experience
The author of these pages is looking for a new gig.
[RESUME]

Engineers and electronic hobbyists: The new Open Symbol Project is creating open schematic symbols and PCB footprints for a variety of different CAD packages.

Mark Whitis's Website Home Page Linux Book: Linux Programming Unleashed My Resume Genealogical Data Contact Info Security About

All email messages received must pass the turing test or they will be considered SPAM. If it could have been written by a machine, it was.

Under no circumstances are you to email me with questions regarding windoze, any other microsoft operating system or application, or any software which runs under any form of windoze.

*