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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:48:58+00:00 2026-06-16T04:48:58+00:00

In the header file I have the following line: typedef int comparator(int* left, int*

  • 0

In the header file I have the following line:

typedef int comparator(int* left, int* right);

But when I tried to write a function definition for it like so:

int comparator (int* left, int* right){
    if(left<right) {
        return 1;
    } else if(right>left) {
        return -1;
    } else {
        return 0;
    }   
}

The error I get is:

file.c:10: error: ‘comparator’ redeclared as different kind of symbol

The function must be typedef’ed because later on in the header file it is used in a method prototype like so:

struct bst_node** search(struct bst_node** root, comparator compare, void* data);

So how is this method constructed?

  • 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-16T04:48:59+00:00Added an answer on June 16, 2026 at 4:48 am

    in your header file you should just have

     int comparator(int* left, int* right);
    

    your aren’t declaring a type, but just declaring a function.

    you could declare a function pointer type called comparator…

    typedef int (*comparator)(int* left, int* right);
    

    but you wouldn’t then make a function called comparator. you just need to make a function with the same signature

    int ascending_comparator(int* left, int* right)
    {
        // comparison
    } 
    

    then call

    search(root, ascending_comparator, data);
    

    Also, I got a feeling you don’t want to be passing int* but actual int, or in your function you don’t want to be comparing the pointers, but comparing the values of what each int is pointing to, like

    int comparator (int* left, int* right){
        if(*left < *right) {
            return 1;
        } else if(*right > *left) {
            return -1;
        } else {
            return 0;
        }   
    }
    

    but possibly you are wanting to compare the memory locations where the ints are stored.

    also your comparisons are the same

    if(left < right) 
    

    is the same as

    if( right > left)
    

    so maybe you want

     int comparator (int* left, int* right){
            if(*left < *right) {
                return 1;
            } else if(*left > *right) {
                return -1;
            } else {
                return 0;
            }   
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have C header file containing the following type definition: // example.h typedef struct
in header file I have defined the following function #ifndef OS_H #define OS_H #include
Please, I have the following line of code to write the header of a
I have setup the following header file to create a Stack which uses an
Let's suppose I have the following line in a CSV file (I removed the
I have the following C++-class: // Header-File class A { public: A(); private: B
I have the following code in a header file: #ifndef BUFFER_H #define BUFFER_H #include
This is really weird.. I have the following redirect in a file: header('Location: http://google.com');
I have .lib file with its header (.h) file. This file have a few
I have a header file buildTree.h and a C file buildTree.c there is a

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.