Home > Software engineering >  how to change typedef struct declaration into a using alias struct?
how to change typedef struct declaration into a using alias struct?

Time:01-28

my struct is defined like this:

typedef struct
{
  int foo;
  char key;
} myStruct;

and I would like to change it to

using struct myStruct = {
      int foo;
      char key;
    } myStruct;

but it seems that something is wrong with it

CodePudding user response:

Yes, you can replace

typedef struct
{
  int foo;
  char key;
} myStruct;

by

using myStruct = struct
{
  int foo;
  char key;
};

But it doesn't make any sense, and you will just confuse readers or possible maintainers of the code.

The established way to go is:

struct myStruct
{
  int foo;
  char key;
};
  • Related