0

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 by cayman: n/a

3
Contributors
5
Replies
8
Views
5 Years
Discussion Span
Last Post by cayman
0

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 by venomxxl: n/a

0

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 by cayman: n/a

0

Whoops missed that semi, good catch

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

typedef unsigned char BYTE;

OK...

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.