This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Struct Enum support for Keil compiler

Hi,
Need information on support of scoped enums in Keil compiler.
My final objective is to use the Enums as AIAction:Enter</i or AIAction:Exit instead of plain Enter or Exit in the source code C files.
This is to solve the global namespace pollution.

I have the following structure in header file :

struct AIAction{
    enum AIActionType
    {
        Enter,
        Exit,
        Run,
    };
};

For using it, following is the code in C file (filetype is C)

    int iType;
    iType = AIAction::Run;

When I compile this with current settings, it is giving me error #618: struct or union declares no named members

However, if I change the filetype to C++, it compiles successfully. So basically C++ compiler is allowing such structure definition.

From this, I infer that C has got limitation of not allowing any non-named members in structures.

How do I use the enums the way I want? Can this be achieved without using C++ compiler?

Parents
  • If you are willing to write AIAction::Run in all of the software, then you can just as well replace : with _ and write AIAction__Run.

    It isn't actually the number of global symbol names that is a reason why global symbol names should be kept down. It's more the complexity of trying to figure out what symbol names are irrelevant when doing a specific operation.

    That's also why a traditional C program normally uses function names that implies some form of namespace, so uart0_init(), uart0_send(), ... while the C++ code would instead have had an object uart0 with member methods.

Reply
  • If you are willing to write AIAction::Run in all of the software, then you can just as well replace : with _ and write AIAction__Run.

    It isn't actually the number of global symbol names that is a reason why global symbol names should be kept down. It's more the complexity of trying to figure out what symbol names are irrelevant when doing a specific operation.

    That's also why a traditional C program normally uses function names that implies some form of namespace, so uart0_init(), uart0_send(), ... while the C++ code would instead have had an object uart0 with member methods.

Children