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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:43:00+00:00 2026-05-20T07:43:00+00:00

int f(struct r); struct r { int a; int b; }; The above snippet

  • 0
int f(struct r);
struct r
{
int a;
int b;
};

The above snippet in a source file throws an error that

warning: its scope is only this definition or declaration,
which is probably not what you want for the line int f(struct r) 

and the following snippet somewhere in the same source file but before the definition of function f(struct r)

struct r emp;
f(emp);

gives an error

error:type of formal parameter 1 is incomplete for the line f(emp)

but the same thing when the struct is replaced by typedef, there were no such such errors…

Is this property to declare an argument in a function declaration before its use is specific to structure alone?

  • 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-20T07:43:01+00:00Added an answer on May 20, 2026 at 7:43 am

    Try the other order:

    struct r { int a; int b; };
    int f(struct r);
    

    If you need the function to be declared before the struct, use a forward declaration:

    struct r;
    int f(struct r);
    ...
    struct r { int a; int b; };
    int f(struct r anR)
    {
        return anR.a + anR.b;
    }
    

    The problem is that during the compilation of int f(struct r); the compiler doesn’t see your structure, so it creates some temporary structure instead. Your declaration of the structure later is from the compiler’s point of view not related to the temporary one.

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

Sidebar

Related Questions

int func(struct x{int a;}y); int main() { } The above code gives following error
I am curious why this code works: typedef struct test_struct { int id; }
Let's say I have a first structure like this: typedef struct { int ivalue;
struct elem { int i; char k; }; elem user; // compile error! struct
I have the following C Header/Code Example: Header file struct category_info { int id;
I have the following code: struct VRfile{ char sessionID[10]; char file[20]; int first; };
Consider the following: typedef struct { int a; int b; int c; int d;
void addNewNode (struct node *head, int n) { struct node* temp = (struct node*)
Given a struct, e.g. typedef struct { int value; } TestStruct; Why does the
I have the following code int ParseData(unsigned char *packet, int len) { struct ethhdr

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.