Designing a C interface for complex types

  Let’s say we are designing an interface to pass a complex type between C++ modules. If there is any possibility of the two modules being built by different compilers, different versions of the same compiler, or for different platforms, we’ll need to use C functions & structures for the interface.  The same is true of C++ to another language. As an example, let’s say our module houses a lookup we want to share: If we wanted to make this lookup available to another module, due to reasons previously stated, we can’t pass our nice C++ types. So, we would need something like this:     So, the implementation of the external-facing function could look something like this:       The code in the caller would look something like this     I don’t love this approach. To be honest, I’ve never liked returning values via parameter. Especially, in functions with several parameters, I think using return values is much clearer to the reader. In this case, it also puts a numbe

Fixing Conan Lock Issues

I've been implementing Conan as our C++ package manager, and I had the following issue cause me a fair amount of grief over the last couple days: [MyPackageName] is locked by another concurrent conan process, wait... If not the case, quit, and do 'conan remove --locks'  You would be forgiven for thinking conan remove --locks should do the trick, but alas, it does not.  After finding hints on several Conan Github issues, I finally figured out that manually removing the package folders in one or both of the following places will alleviate the issue: Windows : C:\Users\username\.conan\data\packagename WSL/Linux : /home/username/.conan/data/packagename

Writing C++ Shared Libraries for Linux

I've recently been getting an old Windows-only module cross compiling for Linux. One of the challenges has been figuring out how to make the consuming project find & properly open the .so file. Most posts suggest that you must put your libraries in a specific folder, but a developer friend with stronger Linux kung-fu than mine confirmed that you can simply drop the .so files in the same directory as your application, & consume them using dlopen. Here's a couple examples: first, a trivial hello world to show the basic consumption, and second, an example of what a reusable interface might look like. The latter shows how to use custom parameter & return types. I am new to designing C interfaces and deploying on Linux, so any comments are welcome. Hello World from a Linux shared library: Passing an interface from a Linux shared library:

With Great Power Comes Great Responsibility

We have failed society, and society has noticed.  Code now powers injustice around the world.... The New York Times recently published an interactive article titled " The Decade Tech Lost Its Way ".  The headline brought to mind a topic I've reflected on often over the past few years.  We have had a decade of headlines exposing aid of government oppression in China by Google, utter disregard for privacy from Facebook, profit-margins above human well-being at Amazon, and many more. The list is not limited to big tech either.  Praiseworthy investigative journalists brought us stories ranging from massive location data-sets collected by dozens of small, obscure companies , to human rights abuses using facial recognition & cell phone spyware by world powers - specifically China & India . (China has now moved people targeted by this technology into brainwashing camps .)  And, of course, abuses of power by my own government as well . These stories both sadden

Using Enums to Replace #define's with Strongly-typed Variables

C++ Map With Multiple Keys

I recently had need for a C++ collection which could be accessed with multiple keys.  Specifically, I had an object that I wanted to look up either by name or id (in O(1) time).  One way to do this is to create two unordered_maps – one keyed by id and another by name, but that is error-prone.  I ended up finding a boost class which will do this. It took me a while get it working, so I thought I would share the result.

Selecting Software Tools

After a software tool is in place, it often extremely difficult to swap it out, so choosing a tool is something you should get right the first time.  However, I find that many companies/teams choose tools for all the wrong reasons.  For example: "This one is free." When comparing options, you will often find at least one open source offering which can be used free of charge.  To be clear, open source is awesome.  The best option for your needs might be open source, but "free" shouldn't be a criteria in most cases.  The Joel Test asks, "Do you use the best tools money can buy?".  Joel used hardware examples, but the concept applies to software tooling as well.  Developer time is typically the biggest expense in a dev shop, so selecting software tools that make devs more efficient is paramount.  Typically, the time cost of using the software will easily eclipse the licensing cost.  Heck, not just developers - sales people, testers, etc. are