You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have had this same issue multiple times in the past week. The primary problem I have been having is calling extern C code with a Chapel type.
For example, the following code is perfectly fine on a 64 bit system because c_long is defined to be an int(64).
use CTypes;
//void myFunc(long x);externproc myFunc(x: c_long);
var x =10;
myFunc(x);
But on a 32 bit system, c_long is a int(32), and so this code fails to compile.
It would be nice to have some kind of tooling (either a compiler warning or a lint warning) that you are trying to pass a Chapel int to a system dependent sized C int. I could imagine something that checks if a Chapel type is being passed to a type that resided in ChapelSysCTypes.
The text was updated successfully, but these errors were encountered:
In my above example, yes the C prototype of myFunc would be long. I've updated the OP to make that clearer. The bug here is not in the C code, but rather its myFunc(x), because x is always a 64 bit integer.
I have hit this several times using the Python C API, which I have no control over.
I agree it'd be nice to have tooling help with this. I'd argue that there isn't really a "bug" here, but that it's part of the ongoing pains that C signed themselves up for by not making their base types have well-defined size (exacerbated by people using them in public interfaces rather than the cstdint types instead). On past supercomputer systems, we used to have the opposite problem where the C compilers would define int to be 64-bits, and lots of existing code would assume it was 32 bits and break as a result.
The safe way to use such functions in Chapel would either be to declare x to be of type c_long as well or to always cast x to c_long when passing it to myFunc, either of which should make the code fully portable. That said, I realize that these are not very ergonomic, so am not suggesting that's what you (or an end-user) would necessarily would want to do.
I have had this same issue multiple times in the past week. The primary problem I have been having is calling extern C code with a Chapel type.
For example, the following code is perfectly fine on a 64 bit system because c_long is defined to be an int(64).
But on a 32 bit system, c_long is a
int(32)
, and so this code fails to compile.It would be nice to have some kind of tooling (either a compiler warning or a lint warning) that you are trying to pass a Chapel int to a system dependent sized C int. I could imagine something that checks if a Chapel type is being passed to a type that resided in
ChapelSysCTypes
.The text was updated successfully, but these errors were encountered: