devxlogo

Avoid Typedefs When Defining Structs

In olden days, before C++ appeared, it was customary to declare a struct as a typedef name. For example:

   typedef struct DATE_TAG  {    int day;    int month;    int year;  } Date;  /* 'Date' is a typedef */

This way, one could create an instance of the struct without having to use the keyword ‘struct’:

      /* C code */  Date date; /* typedef; 'struct' not required */  struct DATE_TAG another_date; /* 'struct' is required */

In C++, the use of a typedef in this context is unnecessary because you don’t need the elaborated type specifier (i.e., struct, union, and class) to create an instance:

     // C++ code  DATE_TAG another_date; // 'struct' not required in C++

Therefore, you shouldn’t declare structs as typedef names anymore.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.