But if your includes are clashing over a name as specific as that - it may be that they are trying to do the same job and are necessarily going to step on each other's toes.
An alternative fix would be to break your sketch up into separate .cpp files, and have each of those only pull in the includes that it needs to do its job.
#define USB_REQ_GET_STATUS 0
and in enum
USB_REQ_GET_STATUS = 0;
Presumably you have an enum somewhere:
enum usb_commands {
USB_REQ_GET_STATUS = 0;
... more
};
This is two separate ways of defining constants. Note that you don't REALLY have a problem, since both values are the same; pick one and get rid of the other. Offhand, I'd say that the "webcam" file has no business defining primitive USB constants, and should simply be including the USB_protocol.h file to get those definitions.
This is two separate ways of defining constants. Note that you don't REALLY have a problem, since both values are the same; pick one and get rid of the other. Offhand, I'd say that the "webcam" file has no business defining primitive USB constants, and should simply be including the USB_protocol.h file to get those definitions.
Thanks, I can see where I went wrong analyzing this issue.
Basically enum symbols cannot be used as #define symbols, if I remove the #defines I would have to change the code to use enum.
I cannot try it right now, but will do it later just to see the compiler output.
I appreciate your reply, It really helps to understand enum "definitions / symbols " in relations to #define.
Thanks again
Jim
Basically enum symbols cannot be used as #define symbols ...
Why not?
Because "#define symbols" are converted by the pre-processor before the compiler gets to look at the code. You can do other variations, or you might have a different definition of "#define symbol", but that's the way I see it:
#define PREPROC_SYMBOL 0
#define PREPROC_SYM2 foo_bar
enum foo {
ENUM_SYMBOL = PREPROC_SYMBOL; /* OK */
PREPROC_SYM2 = 1; /* OK */
PREPROC_SYM2 = PREPROC_SYMBOL; /* OK */
PREPROC_SYMBOL = 2; /* NOT OK */
... more
};
westfw:
Why not?
Because "#define symbols" are converted by the pre-processor before the compiler gets to look at the code. You can do other variations, or you might have a different definition of "#define symbol", but that's the way I see it:
#define PREPROC_SYMBOL 0
#define PREPROC_SYM2 foo_bar
enum foo {
ENUM_SYMBOL = PREPROC_SYMBOL; /* OK /
PREPROC_SYM2 = 1; / OK /
PREPROC_SYM2 = PREPROC_SYMBOL; / OK /
PREPROC_SYMBOL = 2; / NOT OK */
... more
};
There should not be semicolon after each "symbol line" , just comma.
BTW is there a real / special name for symbols used in enum?
Well, yes I agree. In much the same way you can't use the same variable name for different purposes inside your code. Nor can you do:
int foo = 42;
int foo = 42;
The OP said:
if I remove the #defines I would have to change the code to use enum.
I assumed he meant change where they were used. I don't see why such a change is necesssary. In my example above (reply #13) in either case you could write: