-
Notifications
You must be signed in to change notification settings - Fork 2
Description
I'm building C applications using the dwfsdk. This library has a single header file to import (convenient) which contains both function declarations and configuration/enum constants. When I have a single file including "dwf.h", there is no issue. But when I include this file in multiple source files (i.e. a driver wrapper), GCC complains about multiple declarations of the the 197 "const" entries contained within "dwf.h".
I think the correct way to solve this is to replace the consts with typedef enum, as in:
// analog acquisition filter:
typedef int FILTER;
const FILTER filterDecimate = 0;
const FILTER filterAverage = 1;
const FILTER filterMinMax = 2;
can be converted to:
typedef enum {
filterDecimate = 0,
filterAverage = 1,
filterMinMax = 2
} FILTER;
There are a few instances where such a replacement is not quite appropriate, in which case a macro definition is a potential solution.
I'm attaching a version of "dwf.h" which implements this solution (but since github doesn't allow attaching .h files, I have changed
the extension to .txt).
dwf.txt
I have not tested every function in the library (in fact have only tested a few), but it compiles while avoiding multiple definitions and seems to work so far. I have added a few "TODO" comments to highlight potential type conflicts if used with a compiler that doesn't allow implicit type conversion. These can be solved with macro definitions as well if they turn out to cause issues.