linked list - Alias a new name for a function (C) -


i've been trying implement queue structure in c, using implementation of linked list in c.

some functions need queue defined in linked_list.h, , wanted alias new name them; example, alias create_queue() create_list().

since i'm new c programming, looked online way this, , ran topic of function pointers. seemed right way wanted, yet when tried it:

#include "linked_list.h"  typedef list_t queue_t; // list_t list type defined in linked_list.h,                         // functions such create_list()  queue_t (*create_queue)() = null; // setting function pointer null create_queue = &create_list; // aliasing create_queue() create_list() 

when try compile, error , warning:

  • error: redefinition of 'create_queue' different type: 'int' vs 'queue_t (*)()'
  • warning: type specifier missing, defaults 'int'

what missing in code? don't want full solution problem, redirection right way.


this create_list():

list_t create_list(){ /* creates , returns null list, index , value zeroed */ list_t list; malloc(sizeof(list_t));  list.global_index = 0; /* global index keep how many nodes in list, since no loops allowed */ list.total_value = 0; /* total value keep total value of nodes in list, since no loops allowed */ list.head = null; list.last = null;  return list; } 

and struct definitions:

struct int_node { int value; struct int_node * previous; /* needed go previous nodes no loops */ struct int_node * next; };  struct int_list { int global_index; int total_value; struct int_node * head; struct int_node * last; };  /* typedefs */ typedef struct int_node node_t; typedef struct int_list list_t; 

try replace lines:

queue_t (*create_queue)() = null; // setting function pointer null create_queue = &create_list; // aliasing create_queue() create_list() 

with line:

queue_t (*create_queue)() = &create_list; // aliasing create_queue() create_list() 

i had compiling without errors.


Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -