ulong / pointer conversion

17 views
Skip to first unread message

Brent W. Baccala

unread,
Jun 25, 2021, 5:23:44 PM6/25/21
to flint-devel
Hi -

I've got a quick question.

Can I assume in FLINT that conversions are possible between ulong and void *?

Like, can I store an ulong in a variable declared void *?

Specifically, I'm working on adding a multiary multiplication function in fmpz_mpoly, which will work similarly to the existing binary multiplication function, except that it can take an arbitrary number of arguments.

So, instead of a heap data structure storing two indices (into two polynomials), I need a dynamically sized array storing "n" indices.

Currently, mpoly_heap_s uses a void * to access a statically sized data structure with the two indices.

I'm wondering if I can just store an index into my array into that "void *" variable.

Storing a pointer into the array is messy because I need to index a second array as well.

    agape
    brent

Bill Hart

unread,
Jun 25, 2021, 7:37:17 PM6/25/21
to flint-devel
On Fri, 25 Jun 2021 at 23:23, Brent W. Baccala <cos...@freesoft.org> wrote:
>
> Hi -
>
> I've got a quick question.
>
> Can I assume in FLINT that conversions are possible between ulong and void *?

I believe that this doesn't hold for all supported platforms. It's
generally not a portable assumption and we've tried to remove all such
cases.

>
> Like, can I store an ulong in a variable declared void *?
>
> Specifically, I'm working on adding a multiary multiplication function in fmpz_mpoly, which will work similarly to the existing binary multiplication function, except that it can take an arbitrary number of arguments.
>
> So, instead of a heap data structure storing two indices (into two polynomials), I need a dynamically sized array storing "n" indices.
>
> Currently, mpoly_heap_s uses a void * to access a statically sized data structure with the two indices.
>
> I'm wondering if I can just store an index into my array into that "void *" variable.
>
> Storing a pointer into the array is messy because I need to index a second array as well.

I understand that this can be a useful hack. It just isn't portable. I
would think there should be no major portability issue with storing an
int in a void *, but a ulong will cause a problem on machines with 32
bit pointers and 64 bit ulongs.

Bill.

>
> agape
> brent
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "flint-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to flint-devel...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/flint-devel/dab63ad7-4c98-4c14-9bab-8cd4e7a9c995n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages