Sign in Join

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

Mailing lists / fpc-pascal / 2005-12

const pchar parameters?

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

L505

When using pchars, what happens when one does this:

function test(const input: pchar): integer;

Is this a pointer to a pchar? Or is it just a pchar?

i.e. below is bad:
function test(var input: pchar): integer;

So what about a const pchar paramater... Is it a read only pchar, or a read only pointer to a pchar?

L505
Jonas Maebe
to L505
L505 wrote 5 lines
When using pchars, what happens when one does this: function test(const input: pchar): integer; Is this a pointer to a pchar? Or is it just a pchar?

It can be either of those. The compiler is free to choose what it does. All you know for sure is that when you try to assign something to "input", the compiler will throw an error.

x
Jonas

Alain Michaud
to L505: When using pchars, what happens when one does this: function test(const input: pchar):…

Hi everyone,

I would appreciate some advice about the following (I try to be clear and short!):

I am trying to dynamically link a shared library ("libplot.so" from the package: www.gnu.org/software/plotutils ). I do this using "dlopen" and "dlsym". Usually it works very well but this time, I do not understand the "C" prototype in the header file "plot.h":

plPlotterParams * pl_newplparams (void)

The function "pl_newplparams" is supposed create a structure (record) and then return some "pointer" to it. The user is not supposed to access this data directly, so there is NO reference to "plPlotterParams" al all in the header files (plot.h)! How does the C compiler knows what plPlotterParams is then? It just assumes it is a pointer or it looks into the liplot.so file directly? To me this is a mistery!

I now that dlsym will search for the procedure names in the library, but do I have to do that for plPlotterParams as well?

If not, then what type should I use for the return parameter: Pointer? integer? I get an exception as soon as I call the routine. (other routines with simple return types works well of course)

I would apreciate if someone could put me back on the track please!

In order to indicate my level of knowledge, I should mention that so far I could:

1-load the library using "dlopen": error code showed "no error" 2-locate the function using "dlsym": error code showed "no error" 3-made sure that the library is well installed by compiling and running a small C language demo program.

Thank you for reading.

Happy new year

Alain Michaud

amiso

Marco van de Voort
to Alain Michaud
Show quoted text 7 lines
I would appreciate some advice about the following (I try to be clear and short!): I am trying to dynamically link a shared library ("libplot.so" from the package: www.gnu.org/software/plotutils ). I do this using "dlopen" and "dlsym". Usually it works very well but this time, I do not understand the "C" prototype in the header file "plot.h":

(don't, use unit dynlibs that wrap those)

Show quoted text 9 lines
plPlotterParams * pl_newplparams (void) The function "pl_newplparams" is supposed create a structure (record) and then return some "pointer" to it. The user is not supposed to access this data directly, so there is NO reference to "plPlotterParams" al all in the header files (plot.h)! How does the C compiler knows what plPlotterParams is then? It just assumes it is a pointer or it looks into the liplot.so file directly? To me this is a mistery

No idea, I assume that if it is named it must be declared somewhere. However it doesn't really matter if you don't use it, any pointer type will do

Show quoted text 6 lines
I now that dlsym will search for the procedure names in the library, but do I have to do that for plPlotterParams as well? If not, then what type should I use for the return parameter: Pointer? integer? I get an exception as soon as I call the routine. (other routines with simple return types works well of course)

I usually use a pointer to an empty record.

Jonas Maebe
to Alain Michaud: I would appreciate some advice about the following (I try to be clear and short!): I am…
Alain Michaud wrote 9 lines
plPlotterParams * pl_newplparams (void) The function "pl_newplparams" is supposed create a structure (record) and then return some "pointer" to it. The user is not supposed to access this data directly, so there is NO reference to "plPlotterParams" al all in the header files (plot.h)! How does the C compiler knows what plPlotterParams is then?

It is in a header file, otherwise the C compiler will not compile it either. According to https://bugzilla.redhat.com/bugzilla/ attachment.cgi?id=3380, it may be defined like this in plotter.h:

typedef struct plPlotterParamsStruct
{
int (*setplparam) (struct plPlotterParamsStruct *_plotter_params, const char *parameter, void * value);

   void * plparams[33];

}
PlotterParams;

Jonas