Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7846443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:34:56+00:00 2026-06-02T17:34:56+00:00

In typedef and struct namespaces in C vs C++ , one of the comments

  • 0

In typedef and struct namespaces in C vs C++, one of the comments seems to imply that exposing some struct foo is preferable to using typedef along the lines of…

typedef struct foo foo;

…and then using foo instead of struct foo throughout the API.

Are there any downsides to the latter variant?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:34:57+00:00Added an answer on June 2, 2026 at 5:34 pm

    It depends how much you like the word struct. If you feel your program will be made clearer by a liberal sprinkling of struct that and struct tother (you can’t have struct this in C++, of course), then by all means use the struct version.

    Personally, I don’t think that repeating struct provides any benefit and I’m happy to use just the typedef name. And because C++ effectively provides the typedef struct xyz xyz; declaration automatically (it isn’t quite accurate, not least because you can explicitly write that in C++, but it is close enough that you probably don’t have to worry about it), I think it makes perfect sense to use the same in C. The C compiler is happy with it, so I normally use typedef struct tag tag; and then use tag and tag * where needed.


    For an alternative but wholly tenable view, read the Linux kernel coding style guide.


    Note that C2011 allows you to redefine a typedef as long as it aliases the same type:

    ISO/IEC 9899:2011 §6.7 Declarations

    Semantics

    ¶5 A declaration specifies the interpretation and attributes of a set of identifiers. A definition
    of an identifier is a declaration for that identifier that:

    — for an object, causes storage to be reserved for that object;

    — for a function, includes the function body;119)

    — for an enumeration constant, is the (only) declaration of the identifier;

    — for a typedef name, is the first (or only) declaration of the identifier.

    Contrast with C99 where this was not possible:

    ISO/IEC 9899:1999 §6.7 Declarations

    Semantics

    ¶5 A declaration specifies the interpretation and attributes of a set of identifiers. A definition
    of an identifier is a declaration for that identifier that:

    — for an object, causes storage to be reserved for that object;

    — for a function, includes the function body;98)

    — for an enumeration constant or typedef name, is the (only) declaration of the
    identifier.

    This simplifies the creation of type definitions as long as you’re consistent (but only if you have a sufficiently compatible C2011 compiler on each platform of relevance to you).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<iostream> #include<time.h> #include<list> #include<stdlib.h> #include<fstream> using namespace std; typedef struct diskBtNode { int parent;
#include <iostream> using namespace std; typedef struct { char streetName[5]; } RECORD; int main()
I have the below code in stdafx.h. using namespace std; typedef struct { DWORD
#include <iostream> using namespace std; struct Term; struct Node; typedef Term* termPtr; typedef Node*
#include <iostream> #include <vector> using namespace std; typedef struct Record { std::string name; bool
After writing the code below: #include <iostream> using namespace std; typedef struct Node {
//file list.h #include stdafx.h namespace st { struct My_List; typedef My_List list; list* create(const
typedef struct _ut_slot { ucontext_t uc; .... }*ut_slot; static ut_slot* table; //array of the
55 typedef struct pidmap { 56 atomic_t nr_free; 57 void *page; 58 } pidmap_t;
Consider the following: typedef struct { int a; int b; int c; int d;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.