Hi Neil,
On Thu, Oct 30, 2014 at 7:21 PM, Neil Carlson <[log in to unmask]> wrote:
> Malcolm,
>
> Thanks for the information. I'm actually trying to convert some old
> Fortran/C interfacing that is really dicey to use the new interoperability
> stuff, and the interfacing has to deal with 0-sized arrays.
>
> On Thu, Oct 30, 2014 at 6:44 PM, Malcolm Cohen <[log in to unmask]> wrote:
>>
>> Neil Carlson asks:
>>>
>>> Will this work with 0-sized actual arguments? Of course I'm assuming
>>> that the C pointer will never be de-referenced in this case. Basically,
>>> I'm wondering if some sensibly-valued address gets passed.
>>
>>
>> I don't understand. If you don't use the address, and don't deref it, why
>> does its value matter?
>
>
> I don't care at all; it could be any old garbage. My concern was just that
> the setup of the call itself didn't blow up (I imagine mysterious stuff,
> like checking, going on behind the scene where its value would be examined,
> but not by any of my code.)
>
>> and only use C_LOC if the actual argument is nonzero-sized, there is no
>> problem. In the zero-sized case you might want to set the argument to pass
>> to C_NULL_PTR, but even if you pass an undefined C_PTR value, that won't
>> present a problem unless you try to use it.
>
>
> Okay, it sounds like what I need to do I have a MY_C_LOC that returns
> C_NULL_PTR if the array is 0-sized.
I still think you shouldn't be interfacing 0-sized arrays with C, as
it is not supported by the standard. I'll be happy to take a look at
the code tomorrow to see if there is a better way to handle this
issue.
Ondrej
|