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

  • Home
  • SEARCH
  • 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 6233371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:17:14+00:00 2026-05-24T10:17:14+00:00

I have these two structures… typedef struct{ MY_SECOND_STRUCT s1; }MY_FIRST_STRUCT; typedef struct{ int s1;

  • 0

I have these two structures…

typedef struct{
    MY_SECOND_STRUCT  s1;
}MY_FIRST_STRUCT;


typedef struct{
    int s1;
}MY_SECOND_STRUCT;

I prefer this order, I dont want to switch them.
But compiler dont know MY_SECOND_STRUCT at the moment and I get error

error: expected specifier-qualifier-list before ‘MY_SECOND_STRUCT’

I´ve tried add declaration to the top

struct MY_SECOND_STRUCT;

also change definition to

typedef struct{
    struct MY_SECOND_STRUCT  s1;
}MY_FIRST_STRUCT;

but it didnt help.

  • 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-05-24T10:17:14+00:00Added an answer on May 24, 2026 at 10:17 am

    That order is not possible. You have to switch them.

    However, if you declare the member as pointer, then switching is not required:

    struct MY_SECOND_STRUCT; //forward declaration is required though
    
    typedef struct{
        MY_SECOND_STRUCT  * s1;  //now its a pointer
    }MY_FIRST_STRUCT;
    

    Or, in C++ you can use template as:

    template<typename MY_SECOND_STRUCT>
    struct MY_FIRST_STRUCT_T
    {
        MY_SECOND_STRUCT  s1;
    };
    
    struct MY_SECOND_STRUCT
    {
        int s1;
    };
    

    And when you want to use MY_FIRST_STRUCT, just use this typedef:

    typedef MY_FIRST_STRUCT_T<MY_SECOND_STRUCT> MY_FIRST_STRUCT;
    

    Use MY_FIRST_STRUCT now. 🙂

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

Sidebar

Related Questions

I have two identical (but differently named) C structures: typedef struct { double x;
Say I have a database called Poll and have these two table structures. poll
Let's say we have these two classes: public class Base { public static int
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I have these two structures in my domain: Exercise (with subjects, solution, difficulty ext.)
I have two table structures like these: episodes ( episode_id MEDIUMINT(8) UNSIGNED NOT NULL
I have two text files that have these structures: File 1 Column1:Column2 Column1:Column2 ...
I have a function which is passed two structures by reference. These structures are
I have these two pieces of code, wich one is more readable? foreach decimal
I have these two modules : package G1; sub new { my $class =

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.