Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Const objects declared in dwf.h and multiple-inclusion errors #1

Open
keithpenney opened this issue Feb 14, 2023 · 0 comments
Open

Comments

@keithpenney
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant