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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:38:21+00:00 2026-06-15T14:38:21+00:00

I tried to compile something like: struct A { int a; struct B {

  • 0

I tried to compile something like:

struct A
{   int a;
    struct B
    {    int c;
    };
};

Now when I compile this code the compiler gives me a warning message that:

declaration does not declare anything [enabled by default]

I know that I have not defined any instance of struct B. That will mean that I shall not be able to access variable c. Still compiler compiles this code with a warning. What’s the whole point ? Why does not the compiler give a compilation error instead ?

ADDED Info:
The size of the struct A is equal to the size of int on my machine!!

  • 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-15T14:38:22+00:00Added an answer on June 15, 2026 at 2:38 pm

    Because you can do this:

    struct A
    {   int a;
        struct B
        {    int c;
        };
    };
    
    int main()
    {
        struct A a = {1};
        struct B b = {2};
    
        return a.a + b.c;
    }
    

    Note:

    • you need a semicolon after declaring B, which your code is missing
    • this isn’t particularly useful, but I suppose it might serve some documentary purpose (ie,to suggest a relationship or grouping between types)
    • in C++, the second variable would have type A::B, but C doesn’t have the same scoping rules (all structs just belong to the global struct namespace, in effect)

    As to the motivation for allowing it …

    struct Outer {
        struct {
            int b;
        } anon;
        /* this ^ anonymous struct can only be declared inside Outer,
           because there's no type name to declare anon with */
    
        struct Inner {
            int c;
        } named;
        /* this ^ struct could be declared outside, but why force it to be
           different than the anonymous one? */
    
        struct Related {
            double d;
        };
        /* oh no we have no member declared immediately ... should we force this
           declaration to be outside Outer now? */
    
        struct Inner * (*function_pointer)(struct Related *);
        /* no member but we are using it, now can it come back inside? */
    
        struct Related excuse;
        /* how about now? */
    };
    

    Once you’ve allowed nested type declarations like this, I doubt there’s any particular motivation to require there be a member of that type right away.

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

Sidebar

Related Questions

I have something like this in my code: template <typename T> struct A {
i tried something like this: boolean funkyBoolean = true; int array[] = funkyBoolean ?
I tried to compile Ercia Sadun's sample code here , but this error came
This is the full error report that is generated when tried to compile my
We have a java project with dependencies that looks something like this. A ->
I saw someone writing code like this , in a C++ class: int foo
I've noticed that sometimes, C macros are written as something like this: #define foo(bar)
I tried to compile this example: #include <stdio.h> #include <stdlib.h> #include <stddef.h> main(){ size_t
I tried to compile Qt+Webkit statically with MS VS 2008 and this worked. C:\Qt\4.6.2>configure
I have tried to compile some C++ WIN32 code with GCC through DevC++ (MinGW

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.