From ripley @ending from @t@t@@ox@@c@uk  Wed Aug 15 16:05:29 2018
From: ripley @ending from @t@t@@ox@@c@uk (Brian Ripley)
Date: Wed, 15 Aug 2018 15:05:29 +0100
Subject: [Rd] longint
In-Reply-To: <2f3f2125-2cb1-51b8-a5ec-9986a18e698b@gmail.com>
References: <b8cc39c0-2e5b-2157-173b-7341ab687188@gmail.com>
 <2f3f2125-2cb1-51b8-a5ec-9986a18e698b@gmail.com>
Message-ID: <B6423F6B-A085-444B-9119-6B09B9349F78@stats.ox.ac.uk>



> On 15 Aug 2018, at 12:48, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> 
>> On 15/08/2018 7:08 AM, Benjamin Tyner wrote:
>> Hi
>> In my R package, imagine I have a C function defined:
>>     void myfunc(int *x) {
>>        // some code
>>     }
>> but when I call it, I pass it a pointer to a longint instead of a
>> pointer to an int. Could this practice potentially result in a segfault?
> 
> I don't think the passing would cause a segfault, but "some code" might be expecting a positive number, and due to the type error you could pass in a positive longint and have it interpreted as a negative int.

Are you thinking only of a little-endian system?  A 32-bit lookup of a pointer to a 64-bit area could read the wrong half and get a completely different value.

> 
> Duncan Murdoch
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] longint
Brian Ripley