Re: [ooc-compiler] Oberon string to C string
Brought to you by:
mva
|
From: <sgr...@ii...> - 2005-09-22 13:07:15
|
Hi August,
> How do I pass an Oberon string to a C function taking a (constant)
> string parameter? The Oberon code generated by the C header converter
> H2O seems to use `POINTER [CSTRING] TO ARRAY OF CHAR' for `char *',
That is correct. CSTRING declares that a pointer type is really a C string,
and allows you to pass string literals as parameters.
If you want to see some examples, check out the Windows module from the
VisualOberon repository. It has CSTRING declarations for string parameters of
Win32 functions, and these are called in the example programs. Still works for
me with the current version of oo2c.
> however with the code below I get a warning from oo2c: "conflicting
> types for built-in function `puts'".
>
> MODULE Test;
> IMPORT Interface;
> BEGIN
> Interface.puts("Hello there!")
> END Test.
>
> MODULE Interface [INTERFACE "C"];
> TYPE String* = POINTER [CSTRING] TO ARRAY OF CHAR;
> PROCEDURE puts*(s: String);
> END Interface.
oo2c builds prototypes for the procedures declared in your interface module.
My guess is that the message you are seeing is from the C compiler. Its
probably because your definition of puts conflicts with the version in stdio.h.
Under mingw32, puts is defined like this:
_CRTIMP int __cdecl puts (const char*);
Therefore, you should probably have declared:
PROCEDURE puts*(s: String) : LONGINT;
oo2c won't generate a "const" declaration, so you may not be able to get a
completely compatible declaration.
This is a slightly unusual case, as the generated Interface.oh/Interface.d
declarations are only really intended to be used in Oberon-2 or FOREIGN
modules. I suspect that stdio.h is somehow included via the standard oo2c
headers. Check if the above declaration fixes your problem. If not, you might
just have to live with the fact that the declarations cannot be made to
completely agree.
Hope this helps.
Cheers,
Stewart
|