Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

caml/alloc.h prototype for copy_string() should have "const" qualifier for argument #2616

Closed
vicuna opened this issue Nov 23, 2000 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Nov 23, 2000

Original bug ID: 224
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Westley Weimer
Version: 3.0.0
OS: linux
Submission from: user-vcaumjr.dsl.mindspring.com (216.175.90.123)

The prototype for copy_string() in caml/alloc.h should (probably) read:
value copy_string (const char *);
It currently reads:
value copy_string (char ); / not right! */
This prevents proper C/OCAML programs from compiling (without great
contortions)
if the compiler is paranoid about dropping type qualifiers (g++ is an example of

such a compiler: this actually bit me in real life, and in C++ it can be
illegal
to cast from "const char *" to "char *" so there is no easy fix). A stub
procedure
trying to copy a C "const char *" (that it got from a library, say) over to an
OCAML
value using the current copy_string() will be unable to because passing it to
copy_string nominally discards the "const" type qualifier. Since copy_string()
does
not (I presume!) actually modify its arguments, it should be declared "const".
This
should not break any current code but will allow more (correct) code to compile.
I
changed it on my local system and it didn't seem to break anything. You may also

want to do something similar for copy_string_array().

- Wes
@vicuna
Copy link
Author

vicuna commented Nov 26, 2000

Comment author: administrator

Full_Name: Westley Weimer
The prototype for copy_string() in caml/alloc.h should (probably) read:
value copy_string (const char *);

We'll try adding it, but const is generally a pain in the neck because
the contravariance of functions is not handled correctly, so we might
backtrack on this.

such a compiler: this actually bit me in real life, and in C++ it can be
illegal to cast from "const char *" to "char *" so there is no easy fix).

C++ trying to be type-safe ? Ha ha.

-- Damien

@vicuna vicuna closed this as completed Nov 26, 2000
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant