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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:53:43+00:00 2026-05-13T14:53:43+00:00

My professor defined this in the .h file void list_map(INTLIST* list, void (*f)(void *));

  • 0

My professor defined this in the .h file

void list_map(INTLIST* list, void (*f)(void *)); /*Applies a function to each element of the list */

I wrote the function like this:

 void list_map(INTLIST* list, void (*f)(void *))
  {
   INTLIST* pTemp=NULL;

   if (list == NULL)
    {
      //list is empty
    }
   else
      {
       for(pTemp=list; pTemp->next!=NULL; pTemp=pTemp->next)
          {
             f(pTemp); //f is a function pointer we call list map from main like list_map(lst, list_sort)
          }    
      }
  }

I call it in main like this:

  list_map(aList[i], (void*)list_sort);

In windows environment, no complaints, but I have to run this in a Linux environment. I’m using a makefile to compile all of the code and I get this warning and error:

*c++ -O2 -c main.c
main.c: In function ‘int main(int, char**)’:
main.c:53: warning: deprecated conversion from string constant to ‘char*’
main.c:123: error: invalid conversion from ‘void ()(INTLIST)’ to ‘void ()(void)’
main.c:123: error: initializing argument 2 of ‘void list_map(INTLIST*, void ()(void))’
make: *** [main.o] Error 1*

Can somebody help with the error first and then maybe with the warning?

Edit Portion:

Someone asked for the list_sort function, here it is:

 void list_sort(INTLIST* list)
 {
  INTLIST* pTemp=NULL;
  INTLIST* pTemp2=NULL;

  pTemp=list;          //temp pointers to compare node values
  pTemp2=list;

  if (pTemp->next !=NULL)     //move to second node
   {
      pTemp2=pTemp2->next;
   }

  while(pTemp2 != NULL)
   {   
       //we implement a selection sort 
       //check if incoming node->datum with each node in the list
       //swap values if <
      if (pTemp2->datum < pTemp->datum)
         {
         //swap the values
         int temp = pTemp->datum;
         pTemp->datum = pTemp2->datum;
         pTemp2->datum = temp;
         }
         //advance the pointer
      pTemp2=pTemp2->next;
   }
 }
  • 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-13T14:53:44+00:00Added an answer on May 13, 2026 at 2:53 pm

    First: why are you compiling C code as C++?. Please compile it with a C compiler.

    The prototype of list_sort() is:

    void list_sort(INTLIST* list);
    

    and list_map() has the prototype:

    void list_map(INTLIST* list, void (*f)(void *));
    

    This means that the second argument to list_map() is a function that takes a void * argument, and returns void (nothing).

    Now, the C standard guarantees that a conversion of any object pointer to void * and back is OK, so given:

    INTLIST *l;
    /* make l point to a valid INTLIST */
    void *pl = l;
    

    this is OK:

    list_sort(pl);
    

    Note that, list_sort() could have been declared as:

    void list_sort_generic(void *l);
    

    In fact, since your professor is using void * in some places, he wants to extend your lists to be of a generic type at some point.

    Anyway, you can pass an INTLIST * to list_sort() or list_sort_generic(), but list_sort_generic() can be passed any object pointer, whereas list_sort() can only be passed INTLIST * (or a void * which was converted from an INTLIST *).

    Even though list_sort() can take a void *, the signature of list_sort() is not:

    void list_sort(void *l);
    

    So, the function types of list_sort() and list_sort_generic() are not the same, and cannot be interchanged. list_map() expects a function of the kind that list_sort_generic() is, but is getting a function of a different kind.

    Since you can’t change any prototypes, you need a cast. Now, void * is a generic type in C, so you would think such a cast would work. But, as I said before, only object pointers can be converted to void * and back portably—not function pointer type. So, you need to cast list_sort() to the correct type when calling list_map().

    That correct type is void (*)(void *). This is a function returning void and taking a void *.

    Hence, the call should be:

    list_map(aList[i], (void (*)(void *))list_sort);
    

    But, since the type of list_sort() and the type expected by list_map() for its second parameter are not the same, the cast may or may not work. Your professor has given you “not-so-nice” (i.e., wrong) prototypes. Either he should have gone all the way in declaring type-generic functions, or he should have kept everything INTLIST *. By going half-way, he has introduced a complicated cast that shouldn’t have been there, and may not work. I am sure if you bring this to your professor’s attention, he will admit this oversight.

    Hope that helped.

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

Sidebar

Ask A Question

Stats

  • Questions 312k
  • Answers 312k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to free the memory for each element of… May 13, 2026 at 10:30 pm
  • Editorial Team
    Editorial Team added an answer Can you post both the IL and decompiled C# for… May 13, 2026 at 10:30 pm
  • Editorial Team
    Editorial Team added an answer The normal quote character is the back-quote - eg create… May 13, 2026 at 10:30 pm

Related Questions

I am working on a VC++ project under VS2008. My resource files contain some
i want to dispatch messages to specific handlers through a common message processor //
I'd like to code in some pre-processor macros to optionally log some information. For
Is there any disadvantage to using char for small integers in C? Are there
I have an assignment from my programming class, which is very poorly worded... The

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.