0

Can I create a function which produces a new static pointer at each call?

struct a{
    //something
}

void function(){
    struct a* head; //I want every time i call function();
                    //  to create a new static pointer
}
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
rallye
  • 21
  • 5
  • 1
    What do you think that would mean, and why would you want that? – Deduplicator Nov 12 '14 at 00:48
  • i want to insert to A list some elements then to B some elements and then again to A list some elements(and all these from the same function).I thought that i can succeed that by using global pointers. – rallye Nov 12 '14 at 00:50
  • what is static pointer? – Bryan Chen Nov 12 '14 at 00:51
  • global! if you say static int *a you can declare a global pointer from a function – rallye Nov 12 '14 at 00:54
  • 2
    Seems you actually want dynamic memory, look for `malloc` and `free`, any tutorial should include them. – Deduplicator Nov 12 '14 at 00:54
  • 1
    I think you might have some confusion over the use of the [static keyword](http://stackoverflow.com/questions/572547/what-does-static-mean-in-a-c-program) in C. If you're thinking of using a static pointer to hold onto the value between function calls... don't. Is the function called multiple times? Is the only purpose of the function to add items to a list? – Francesca Nannizzi Nov 12 '14 at 00:58
  • yes the function is called multiple times!I want a function similar to insertion(); in which I can insert to A list some elements then to B some elements and then again to A list some elements as I said before – rallye Nov 12 '14 at 13:55

0 Answers0