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 6923453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:32:16+00:00 2026-05-27T10:32:16+00:00

Following a C tutorial , I’ve encountered a type dependency that I don’t know

  • 0

Following a C tutorial, I’ve encountered a type dependency that I don’t know how to resolve. So far, we had this:

typedef long SetStringPtr( char * );
typedef long GetStringPtr( char *, long );

typedef struct {
    SetStringPtr * SetString;
    GetStringPtr * GetString;
} IExampleVtbl;

typedef struct {
    const IExampleVtbl * lpVtbl;
    DWORD count;
    char  buffer[80];
} IExample;

No problem. Now, it’s changing to include a THIS pointer:

typedef long SetStringPtr( IExample *, char * );
typedef long GetStringPtr( IExample *, char *, long );

typedef struct {
    SetStringPtr * SetString;
    GetStringPtr * GetString;
} IExampleVtbl;

typedef struct {
    const IExampleVtbl * lpVtbl;
    DWORD count;
    char  buffer[80];
} IExample;

The definitions depend on each other in a circular way. The cl.exe compiler shows lots of syntax errors because by the time I use IExample it hasn’t been declared yet. How can I resolve this?

Compile with cl.exe /W4.

Update

Thanks – three moreless equivalent answers at the same time, I could have chosen any one of them.

So, to resume, what choices do you have to make when solving this problem? First, naming convention – append _t to typedefs, or _s (or Struct) to structs? Probably a matter of taste. Then, whether you want to have the forward definition as part of a typedef or as part of a struct. Probably also a matter of taste. Here’s the problem in another form and three ways to solve it:

/* won't compile */
typedef struct {
        B * b;
        C * c;
} A;

typedef struct {
        A * a;
        C * c;
} B;

typedef struct {
        A * a;
        B * b;
} C;

First solution:

struct B_s;
struct C_s;

typedef struct {
        struct B_s * b; // typedef not available yet
        struct C_s * c; // ditto
} A;

typedef struct {
        A * a;
        struct C_s * c; // ditto
} B;

typedef struct {
        A * a;
        B * b;
} C;

Second solution:

typedef struct B_s B;
typedef struct C_s C;

typedef struct {
        B * b;
        C * c;
} A;

// typedef struct ... B => change to:
struct {
        A * a;
        C * c;
} B_s;

// typedef struct ... C => change to:
struct {
        A * a;
        B * b;
} C_s;

And the third (and most symmetrical) solution:

struct A_s;
struct B_s;
struct C_s;

typedef struct A_s A;
typedef struct B_s B;
typedef struct C_s C;

struct {
        B * b;
        C * c;
} A_s;

struct {
        A * a;
        C * c;
} B_s;

struct {
        A * a;
        B * b;
} C_s;
  • 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-27T10:32:16+00:00Added an answer on May 27, 2026 at 10:32 am
    typedef struct IExample_s IExample;
    
    typedef long SetStringPtr( IExample *, char * );
    typedef long GetStringPtr( IExample *, char *, long );
    
    typedef struct {
        SetStringPtr * SetString;
        GetStringPtr * GetString;
    } IExampleVtbl;
    
    struct IExample_s {
        const IExampleVtbl * lpVtbl;
        DWORD count;
        char  buffer[80];
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been following this tutorial (lesson 6) in order to build and deploy a
I'm following this tutorial (seems good) for Rails. After I run ruby script/generate scaffold
I was following this tutorial . I need to use a php file's ouput
I am following this tutorial and I've run the command ruby script\server and successfully
Hi Guys I don't quite understand the following tutorial question: write a ADT sorted
I am playing with my Xcode, following tutorial, learning this stuff. I added an
I'm trying the following tutorial: http://henrik.nyh.se/2007/03/ruby-wordwrap-method It has a block that needs to be
I'm a newbie learning Javascript. In the following tutorial, I don`t understand why value
Following a tutorial on the internet regarding Soap development with Java, I found this
Following this tutorial: http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html Tiles configuration ( tiles.xml ) : <?xml version=1.0 encoding=UTF-8 ?>

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.