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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:18:25+00:00 2026-06-06T03:18:25+00:00

In gcc it is possible to create an anonymous struct, like this: struct test2

  • 0

In gcc it is possible to create an anonymous struct, like this:

struct test2 {
    struct {
            int x;
            int y;
    };
    int z;
};

But when I try to do the same thing with a pre-defined version of the anonymous struct, it fails:

struct test1 {
    int x;
    int y;
};

struct test2 {
    struct test1;
    int z;
};

The reason I want to do this is that I want to define a struct which contains a set of function pointers corresponding to “member functions” of a C class. If I don’t include the struct anonymously, then I wind up having to do something obnoxious like this:

object->API->function(object,...);

which just plain doesn’t work for some things I need to do (for instance, since “object.API” doesn’t match “object”, it makes it difficult or impossible to do automatic bindings from other languages which support hiding of the object pointer.)

At the moment, I just copy/paste the functions, but this is tedious and error prone. I could use the C pre-processor, but it seems just ugly to create a macro which has a bunch of function prototypes in it.

  • 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-06T03:18:26+00:00Added an answer on June 6, 2026 at 3:18 am

    struct test1 is the name of the type of the struct. You are lacking a name for the field (and you cannot have “anonymous” fields other than inline-defined structs or unions).

    struct test2 {
        struct test1 myStructTest1;
        int z;
    };
    

    EDIT: Apparently there’s a GCC extension that allows you do that: -fms-extensions

    Unless -fms-extensions is used, the unnamed field must be a structure or union definition without a tag (for example, struct { int a; };'). If -fms-extensions is used, the field may also be a definition with a tag such asstruct foo { int a; };’, a reference to a previously defined structure or union such as `struct foo;’, or a reference to a typedef name for a previously defined structure or union type.

     struct s1 { int a; };
     struct s2 { struct s1; };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running Solaris, so it's possible that this is specific to running GCC on
I know it's possible to separate to create a pointer to member function like
I'm aware of this question which mentions Boost's STATIC WARNING, but I'd like to
Currently I use something like this to create project make files: cmake -DCMAKE_INSTALL_PREFIX=./install-dir -DBUILD_WITH_STATIC_CRT=ON
i'm working on gcc , i'm wondering if this is possible: I have a
Is it possible in GCC to use a struct or class as a vector
Is it possible to install gcc in iPhone (3.0 or above) with out jailbreaking
Is it possible to bring GCC into an infinite loop by inputting strange source
With gcc (and possibly other compilers as well) it's possible to define a macro
(Running MingW on 64-bit Windows 7 and the GCC on Kubuntu) This may possibly

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.