Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Lalle

double asterisk

This topic is 6114 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What does it mean when a function has the following decleration? void MyFunc(int **a); What does it mean when you have two asterisks like this? Thanks

Share this post


Link to post
Share on other sites
Advertisement
The fun of pointers increases dramatically as the number of asterisks increases! Hurray for dereferencing!

Share this post


Link to post
Share on other sites
They are also used to modify the address of a pointer, ie
void f()
{
char *Thingy = "Hello\nThere";

// Thingy = "Hello...
NextCRString( &Thingy );
// Thingy = "There"
}

void NextCRString( char **a )
{
while( (*a) != ''\n'') ) a++;
(*a)++;
}

Could also use

void NextCRString( char *&a ); so you dont have to pass the address of Thingy and derefence a.


[The views stated herein do not necessarily represent the view of the company Eurocom ]

Eurocom Entertainment Software
www.Eurocom.co.uk

The Jackal

Share this post


Link to post
Share on other sites
If you want a function to reallocate a pointer the pointer will either have to be passed by reference (which isn''t possible in C), or as a pointer to a pointer.

Consider the following:
  
void myFunctionThatDoesntWork (MyStruct* s) {
free (s);
s = (MyStruct*)malloc(sizeof(MyStruct)); // WRONG, only

// local copy of

// s is reallocated

}

void myFunctionThatWorks (MyStruct** s) {
free (*s);
*s = (MyStruct*)malloc(sizeof(MyStruct)); // CORRECT

}

void myCPlusPlusFunctionThatWorks (MyStruct*& s) {
delete s;
s = new MyStruct(); // CORRECT

}


-Neophyte

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!