Skip to content

Fix -Wpointer-to-int-cast warnings in *memory.c on Windows#175

Open
rgommers wants to merge 1 commit intoxiaoyeli:masterfrom
rgommers:fix-pointer-subtraction
Open

Fix -Wpointer-to-int-cast warnings in *memory.c on Windows#175
rgommers wants to merge 1 commit intoxiaoyeli:masterfrom
rgommers:fix-pointer-subtraction

Conversation

@rgommers
Copy link
Copy Markdown

@rgommers rgommers commented Apr 2, 2026

On Windows, long int will be 32-bit, and stack.used is int_t which can be 64-bit. This results in warnings like (from scipy/scipy#24924):

[37/344] Compiling C object scipy/sparse/linalg/_dsolve/libsuperlu_lib.a.p/SuperLU_SRC_cmemory.c.obj
../scipy/sparse/linalg/_dsolve/SuperLU/SRC/cmemory.c(663,24): warning: cast to smaller integer type 'long' from 'char *' [-Wpointer-to-int-cast]
  663 |     Glu->stack.used -= (long int) fragment;
      |                        ^~~~~~~~~~~~~~~~~~~
../scipy/sparse/linalg/_dsolve/SuperLU/SRC/cmemory.c(664,24): warning: cast to smaller integer type 'long' from 'char *' [-Wpointer-to-int-cast]
  664 |     Glu->stack.top1 -= (long int) fragment;
      |                        ^~~~~~~~~~~~~~~~~~~

The fix needs to use a double cast for correctness: only intptr_t is defined for pointer to integer casting, and then we need to cast again to int_t to match stack.used.

On Windows, `long int` will be 32-bit, and `stack.used` is `int_t`
which can be 64-bit. This results in warnings like:
```
[37/344] Compiling C object scipy/sparse/linalg/_dsolve/libsuperlu_lib.a.p/SuperLU_SRC_cmemory.c.obj
../scipy/sparse/linalg/_dsolve/SuperLU/SRC/cmemory.c(663,24): warning: cast to smaller integer type 'long' from 'char *' [-Wpointer-to-int-cast]
  663 |     Glu->stack.used -= (long int) fragment;
      |                        ^~~~~~~~~~~~~~~~~~~
../scipy/sparse/linalg/_dsolve/SuperLU/SRC/cmemory.c(664,24): warning: cast to smaller integer type 'long' from 'char *' [-Wpointer-to-int-cast]
  664 |     Glu->stack.top1 -= (long int) fragment;
      |                        ^~~~~~~~~~~~~~~~~~~
```

The fix needs to use a double cast for correctness: only `intptr_t` is
defined for pointer to integer casting, and then we need to cast again
to `int_t` to match `stack.used`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant