0

Possible Duplicate:
returning multiple values from a function

I'm trying to make a doubly linked list in C. I have a main function that calls another function to create nodes and build the list. I need this last function to return two different pointers (one to the start and one to the end of the list) to main. Is there a way to use "return" to return two things? In this case two pointers. I thought in returning a structure with two elements, the two pointers. But is there an easy way?

This is how I call the function (insertacomienzo) in the main:

primero = insertacomienzo (primero, ultimo, tamaniomax);

(primero is a pointer) And the function returns this pointer now modified.

return primero;

What I need is to return now two pointers, one is the one pointing to the start of the list, and the other is pointing to the end of the list.

Thank you!

Community
  • 1
  • 1
LeanDroid
  • 43
  • 1
  • 2
  • 8
  • 1
    Pass by reference and set the values in the functions. – ata Nov 06 '12 at 17:40
  • the code is pretty long (it's a work for the university), so it would be really confusing.. I will try to simplify this particular case and edit the question. – LeanDroid Nov 06 '12 at 17:41

1 Answers1

0

Use InOut parameters to give back any extra parameter (this is how it's usually done in C). InOut parameters are of type '*' instead of just '' (in CPP they are of type '&*' but you don't have '&' in C)

Here is a prototye of a inout function

node* GenerateList(node* currentListItem,node** InOutLastListItem,int currentNodes)
MichaelCMS
  • 4,703
  • 2
  • 23
  • 29