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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:17:13+00:00 2026-06-17T07:17:13+00:00

I wanted to ask about Forward Declarations in C. How generally they work. For

  • 0

I wanted to ask about Forward Declarations in C. How generally they work.
For example if in a file I declare

struct task_struct;

and define the struct in other file will it work? Because as far as I know Compiler must know the size of variable that is being declared. If it does then how does compiler actually handles such type of requests?

I found the above example in Linux Source code that got me interested.

  • 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-17T07:17:15+00:00Added an answer on June 17, 2026 at 7:17 am

    Once you use a forward declaration, the type becomes Incomplete type for the compiler.
    Compiler does not know anything about the size or layout of the type and hence you cannot perform any operation which needs the compiler to know these.

    In C, If you forward declare a type, you can only use a pointer to that type. Since pointers to all structure types need same size[Note], the compiler is just happy to know that it has a pointer to a type.

    If I forward declare a structure and define it other file will it work?

    It will as long as you only use a pointer to the structure in the file which forward declares the structure. If you dereference the pointer you will get errors, Since compiler is not aware of the layout of the Incomplete type.


    [Note] Thanks to melpomene & Daniel for this clarification.

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

Sidebar

Related Questions

just wanted to ask where I define initial class properties? From other languages I
I wanted to ask about winApi 32 custom icons creation. When I define icon
Just wanted to ask you about the drawbacks (I mean memory or reponse time)
I wanted to ask about using selector from a variable first I have: function
I know this has been discussed yet I wanted to ask about the current
I wanted to ask a question about server data. I am new to server
I wanted to ask a clever question about using Canvas as a container, but
I wanted to ask the SO community about this problem in my project. I
I am new to rspec and wanted to ask how one would go about
I wanted to ask about the pros cons of my the following OOP style.

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.