Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-11

Pointer to a const char

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alexander

How can I describe a "pointer to a constant char" in FreePascal?

For example this C function:

int some_func(const char *arg, ...);

My guess in FreePascal is this(with ctypes unit):

function some_func(const arg: pcchar): cint; cdecl; external;

A constant argument to a function.
I'm not sure, is it a "constant pointer to a char", or a "pointer to a constant char".

Alex
Michael Schnell
to Alexander
Alexander wrote 13 lines
How can I describe a "pointer to a constant char" in FreePascal? For example this C function: int some_func(const char *arg, ...); My guess in FreePascal is this(with ctypes unit): function some_func(const arg: pcchar): cint; cdecl; external; A constant argument to a function. I'm not sure, is it a "constant pointer to a char", or a "pointer to a constant char".

In fact in c const "char *arg" does not mean a constant pointer to a character, but a pointer to a constant character,

As in C you need to pass explicit pointers and in Pascal you can do this implicitly by using var or const, I suppose

function some_fuc(const arg: char): cint; cdecl; external;

should do this.

-Michael

Antonio Fortuny
to Alexander: How can I describe a "pointer to a constant char" in FreePascal? For example this C…
Alexander wrote 5 lines
How can I describe a "pointer to a constant char" in FreePascal? For example this C function: int some_func(const char *arg, ...);

... coulb be translated to

some_proc(const arg: PChar, ...);

where the argument cannot be changed in any way (the compiler complains) but the data to which the argument points can be freely changed, thus: (arg + offset)^ := #0; works
I don't know a way to make the data pointed to, as being constant. Have a look athttp://www.freepascal.org/docs-html/ref/refsu61.html#x160-17000014.4.4

Antonio.

Show quoted text 8 lines
My guess in FreePascal is this(with ctypes unit): function some_func(const arg: pcchar): cint; cdecl; external; A constant argument to a function. I'm not sure, is it a "constant pointer to a char", or a "pointer to a constant char".

The first one applies.

Show quoted text 8 lines
-- Alex _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Sita Software *Antonio Fortuny* Senior Software engineer 220, avenue de la Liberté L-4602 Niederkorn Tel.: +352 58 00 93 - 93 www.sitasoftware.lu <http://www.sitasoftware.lu> Your IT Partner