Mike Taylor
Mike Taylor

Reputation: 2524

What is the Delphi equivalent of ' unsigned char** ' in C

What is the Delphi equivalent of

unsigned char** ' 

in C

i'm not sure if its a pointer to an array or a pointer to a pointer or if the two things are the same in C.

Upvotes: 2

Views: 4594

Answers (4)

Michał Niklas
Michał Niklas

Reputation: 54322

EDIT In C both pointer to an array and pointer to a pointer have different meaning to the compiler (thanks caf).

In C arrays are simply block of memory. There is no such function like Length(array), Low(array) or High(array) that you can use on Pascal arrays. For practical purpose to Pascal programmers C arrays can be usually ported to Pascal pointers, especially on function calls to various API.

If we assume that usigned char can be translated to byte in Delphi, then unsigned char * can be translated to ^byte that is usually done via type declaration that can look like:

type
  PByte = ^byte;
  PPByte = ^PByte;

If you are trying to convert some C code, especially .h header file then look at headconv.

Upvotes: 4

Steve M
Steve M

Reputation: 8516

A pointer to a pointer and a pointer to an array are NOT the same thing.

unsigned char** p1;
unsigned char* p2[N];
unsigned char (*p3)[N];

p1 is a pointer to a pointer to an unsigned char. It could point to an element in p2, which is an array of pointers to unsigned char. p3 is a pointer to an array of unsigned char. Check out the C FAQ for more details. Edit: Here's a better example.

Upvotes: 4

it is a pointer to a pointer.

It is only a pointer to a pointer. {*}

But the pointer indexing convention means that it is usable for accessing an array or pointers. The first place you typically see this thing is

int main(int argc, char** argv)

and this is an example of using it to index into an array of char*s (the allocation and structuring of which was managed by the OS).


{*}Because an array and a pointer are not the same thing in c. Rather an array "decays" to pointer when used in a pointer context.

Upvotes: 2

Mason Wheeler
Mason Wheeler

Reputation: 84590

The two are the same in C. But usually when you see that, that's an array of char pointers. I'd declare it like this:

type
  PAnsiCharArray = ^TAnsiCharArray;
  TAnsiCharArray = array[0..0] of PAnsiChar;

Ugly, but then again so is most stuff that has to interact with C code. It should work, though.

Upvotes: 4

Related Questions