Member Avatar for cayman

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;
}

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
}

someFunc(ptrToArray); By the way, there is no BYTE in C

Member Avatar for cayman

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;

Whoops missed that semi, good catch

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

typedef unsigned char BYTE;

OK...

Member Avatar for cayman

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.