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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:16:57+00:00 2026-06-15T06:16:57+00:00

Extending from this question I am having trouble to understand this code. struct foo

  • 0

Extending from this question

I am having trouble to understand this code.

struct foo myfoo;  // --> Is it forward declaration or object creation. ?

struct foo
{
 int a;
};

int main()
{

return 0;
}

In the code marked arrow --> Is it forward declaration or object creation. ?

If that is forward declaration then what is struct foo; called ? If it’s object creation or instantiation then how can it create object before struct definition.

On gcc compiler its working fine but other compiler gives error.

gcc -Werror -Wall tst.c -o tst

Any suggestion or explanation about this behavior of gcc? I could not have found anywhere it as documented.

  • 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-15T06:16:58+00:00Added an answer on June 15, 2026 at 6:16 am

    Looks like tentative definition of myfoo and because the definition of the struct is provided you get no error.

    clang provides a comprehensive diagnostic when the type in not defined.

    prasoon@ats-VPCEB3AGG:~$ cat tst.c
    struct foo myfoo;
    
    //struct foo{
    //  int x ;
    //} ;
    
    int main()
    {
    }
    prasoon@ats-VPCEB3AGG:~$ clang tst.c
    tst.c:1:12: error: tentative definition has type 'struct foo' that is never
          completed
    struct foo myfoo;
    

    I don’t think its a gcc bug, clang as well as comeau online is compiling the code.

    $6.9.2/2

    A declaration of an identifier for an object that has file scope without an initializer, and
    without a storage-class specifier or with the storage-class specifier static, constitutes a
    tentative definition. If a translation unit contains one or more tentative definitions for an
    identifier, and the translation unit contains no external definition for that identifier, then
    the behavior is exactly as if the translation unit contains a file scope declaration of that
    identifier, with the composite type as of the end of the translation unit, with an initializer
    equal to 0.


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

Sidebar

Related Questions

Extending from this questions about locales And described in this question : What I
Extending this question: How to Create several files from a list in a text
This post derives from my question extending cell definition to cellframelabels . I've been
I'm extending a constructor class' functionality via the prototype method, but I'm having trouble
I am just extending my this question a bit. I have my App_LocalResources in
I'm extending the UserProfile but I'm having trouble getting the new field - current_article
The gist of this question is about extending a class, minimizing jam-packing everything into
EDIT: looking for this: http://diminishing.org/extending-formtastic-with-a-sprinkle-of-jquery (If this works I'll answer my own question) I've
Sorry just clearing my questions. Extending this question Optimizing sqlite query I have a
Extending to my own question from My Earlier post If you notice i am

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.