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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:13:30+00:00 2026-05-14T02:13:30+00:00

I am doing a recursive program and I am getting an error about conflicting

  • 0

I am doing a recursive program and I am getting an error about conflicting types:

void* buddyMalloc(int req_size)
{ 
     // Do something here
     return buddy_findout(original_index,req_size); // This is the recursive call
}

void *buddy_findout(int current_index,int req_size)
{
    char *selected = NULL;

    if(front!=NULL)
    {
        if(current_index==original_index)
        {
            // Do something here
            return selected;
        }
        else
        {
            // Do Something here
            return buddy_findout(current_index+1,req_size);
        }
    }
    else
    {
        return buddy_findout(current_index-1,req_size);
    }
}

Error:

buddy.c: At top level:
buddy.c:76: error: conflicting types for ‘buddy_findout’
buddy.c:72: note: previous implicit declaration of ‘buddy_findout’ was here

Please note the file buddy.c in which I am defining this does not contain main and is linked with several other .c files.

  • 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-14T02:13:30+00:00Added an answer on May 14, 2026 at 2:13 am

    You can’t use a function prior to its proper definition without a prototype. buddy_malloc() is using buddy_findout() before it is prototyped or defined, which the compiler will treat as a definition.

    Prototype buddy_findout() prior to defining buddy_Malloc(), or define buddy_findout() prior to defining buddy_Malloc().

    I suggest prototypes, i.e:

    void *buddy_Malloc(int);
    void *buddy_findout(int, int);
    

    … Just under your last #include

    This avoids any confusion on the order that you define things. Also, consider using size_t (the largest unsigned int type available on the architecture) instead of signed integers when specifying sizes.

    Here is your code (corrected) using both methods. Method 1 – using prototypes:

    void *buddy_Malloc(int);
    void *buddy_findout(int, int);
    
    void* buddyMalloc(int req_size)
    { 
              //Do something here//
             return buddy_findout(original_index,req_size); //This is the recursive fn I call//
    }
    
    void *buddy_findout(int current_index,int req_size)
    {
         char *selected = NULL;
    
         if(front!=NULL)
          {
                if(current_index==original_index)
                {
                        //Do something here//
                         return selected ; // 
                 }
                 else
                 {
                     //Do Something here//
                     return buddy_findout(current_index+1,req_size);
                  }
            }
           else
            {
                      return buddy_findout(current_index-1,req_size);
             }
    }
    

    And method 2, just re-ordering:

    void *buddy_findout(int current_index,int req_size)
    {
         char *selected = NULL;
    
         if(front!=NULL)
          {
                if(current_index==original_index)
                {
                        //Do something here//
                         return selected ; // 
                 }
                 else
                 {
                     //Do Something here//
                     return buddy_findout(current_index+1,req_size);
                  }
            }
           else
            {
                      return buddy_findout(current_index-1,req_size);
             }
    }
    
    void* buddyMalloc(int req_size)
    { 
              //Do something here//
             return buddy_findout(original_index,req_size); //This is the recursive fn I call//
    }
    

    In some circles it is sort of considered an art to not need prototypes for static functions, it kind of demonstrates the program was planned out in someone’s head before code was written. I don’t have much to say about that either way, other than recommending prototypes even for static functions to those who are still learning the nuts and bolts of C.

    If buddy_* is going to be exposed for other modules to use, you really need prototypes. Its hard to tell if you intend these to be static or not.

    Edit:

    If you are putting the prototypes in an external header file, you need to use include guards to ensure that each module includes them only once (and doesn’t re-define them to be the exact same thing).

    Here is a sample buddy.h:

    #ifndef BUDDY_H
    #define BUDDY_H
    
    void *buddy_Malloc(int);
    void *buddy_findout(int, int);
    
    #endif /* BUDDY_H */
    

    The preprocessor will then keep your modules from throwing that error.

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

Sidebar

Related Questions

No related questions found

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.