Hello,

On Fri, Sep 23, 2022 at 07:08:26AM +0200, Peter Kovacs wrote:

> Hi all,
> 
> We cast int to (void*) -> (example in main/sw/source/ui/fldui/changedb.cxx 
> line 234)
> 
> In general this sounds like not a sane idea to me, see discussions [1] [2]
> [3]. The solution that the c++ community found is the use of intptr_t, which
> is defined in C99.
> 
> In general I would like to get rid of these casts. However as a quick fix it
> would make sense to use intptr_t as a first measure.

IMHO casting int to void* is not as bad as it seems.

Your cited sources explains that there would be problems with
_round-tripping_ i.e. using an int type to pass a pointer.

The reason is that on some architectures pointers (void*) are
represented with more bits than integers. Notable example: Linux on
x86_64.

As long as we are using pointers as ``general purpose integers'' we
should have no problems because they are ``big enough'' to contain any
integer value _and_ any pointer.

> Is there any reason that would block the move to C99? I guess C99 should be
> supported by all the compilers we require . (c11 is currently not available
> on all Plattforms we support.)

Unfortunately, Visual Studio 2008 does not support C99.  Specifically
for this case, it is missing the definition of the intptr_t type.

Wikipedia [4] gives more information about C99 support in Visual Studio.

I hope this helps.

> [1] 
> https://stackoverflow.com/questions/26805461/why-do-i-get-cast-from-pointer-to-integer-of-different-size-error
> 
> [2] 
> https://stackoverflow.com/questions/25381610/cast-int-to-pointer-why-cast-to-long-first-as-in-p-void-42
> 
> [3] 
> https://stackoverflow.com/questions/6326338/why-when-to-use-intptr-t-for-type-casting-in-c

[4] https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#C

-- 
Arrigo

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@openoffice.apache.org
For additional commands, e-mail: dev-h...@openoffice.apache.org

Reply via email to