Skip to main content
gamedev.net
🔒 Locked

argh. pointers to pointers...

Started by keethrus Dec 8, 2002 at 3:36 PM 0 replies 100+ views
Original Post
keethrus
keethrus
im creating a function which gets passed a pointer to a pointer, and i want the function to change what the pointer in the calling function points to. ex: main source file
  
// MAIN

#include "myHeader.h"

void main()
{
    Uint8 *errmsg;

    if ( some_func(&errmsg) == -1 )
    {
        // function failed, print out its error message

        printf("error: %s\n", errmsg);
    }
    else
    {
        // function was successful, do whatever

    }
}
  
myHeader.h
  
const Uint8 myReturnErr[] = "couldnt do something (whatever).";

Uint32 some_func(Uint8 **err)
{
    // do whatever


    // if fail, make pointer point to ''myReturnErr''.

    *err = myReturnErr[0];
    return -1;

    // if successful, just return 0 (success)

    return 0;
}
  
this doesnt compile, im getting a "assignment discards qualifiers from pointer target type" error. so how would i go about doing this? having the called function change what a passed pointer points to so that when the function returns, the pointer in the calling function will point to something different? thanx, - jeremiah inlovewithGod.com
Evil Bill
Evil Bill
Its because myReturnError is a const Uint8*.
Try this:

  
typedef const Uint8* STRING;
Uint32 some_func(STRING* err)
...


And that should work. (I think :s)

Member of the Unban Mindwipe Society (UMWS)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.