Hi Folks

Im rusty on my pointer passing

I would like to pas an array (or pointer thereof) to a function, for use within that function.

I cant remember the correct syntax, if somebody could help me out, that'd be FAB
heres where I am at

int main (void) {
    BYTE arrayOfByte[]
    BYTE *ptrToArray = &arrayOfByte;
    ...
    someFunc(*ptrToArray);
    ...
    return 0;
}

void someFunc (BYTE *foo) {
    *foo[3] = 0xFF; //put FF into arrayOFByte[3]
    return 0;
}

Edited 5 Years Ago by cayman: n/a

I think BYTE arrayOfByte[]; (add a semicolon...) would be a pointer too (I'm not sure because I've never used [] instead of a pointer).

The rest of your code:

int main()
{
    BYTE arrayOfByte[];
    BYTE *ptrToArray = arrayOfByte;
    //...
    someFunc(ptrToArray);
    //...
    return 0;
}

void someFunc (BYTE *foo)
{
    foo[3] = 0xFF; //put FF into arrayOFByte[3]
    // return 0; - return type is void
}

Edited 5 Years Ago by venomxxl: n/a

Ah so I need to drop the * when Im passing it, thanks
Whoops missed that semi, good catch
...and the return on auto pilot !

didnt think I needed to add the type def in...

typedef unsigned char BYTE;

Edited 5 Years Ago by cayman: n/a

Whoops missed that semi, good catch

didnt think I needed to add the type def in...

typedef unsigned char BYTE;

OK...

Thanks venomxxl and waltp, that got me on the right track

This question has already been answered. Start a new discussion instead.