0

I have a legacy C source file which defines an enum.

//source.c
typedef enum
{
    ENUM_0,
    ENUM_1,
    ENUM_2
} my_enum;

How can I use this enum inside my unit test's source code?
I can think of 2 options:
1. Copy paste the typedef into my source code. It can cause the test to break if the typedef changes in the original file.
2. Use #include "source.c" in my unit test's file. It ends up with bad module seperation.

Thanks

noti
  • 887
  • 7
  • 25
  • Move the typedef to a header and include that? – Daniel Fischer Feb 03 '13 at 15:50
  • This is a good idea, but I'm trying to keep the legacy code unchanged. – noti Feb 03 '13 at 15:53
  • 1
    Why would you like to use a module private (enum) type out side the module? If it's exposed by the module's interface it should be defined in the module's header. – alk Feb 03 '13 at 15:56
  • If you don't want to modify the original code, then those are just about your only two options. Other than using some sort of parsing tool to pull out the regex definition as part of your build process. – Oliver Charlesworth Feb 03 '13 at 16:03
  • 1
    I think the best practice is to extract the private typedef into a private header file. Although this is a change in the legacy code which I wanted to avoid, but it is cleaner and more flexible. Thanks – noti Feb 03 '13 at 16:14
  • Is there a preferred naming convention for private header files? – noti Feb 04 '13 at 07:51

0 Answers0