RFR (M): 8184334: Generalizing Atomic with templates

Andrew Haley aph at redhat.com
Fri Aug 4 08:54:02 UTC 2017


Hi,

On 04/08/17 00:42, David Holmes wrote:
> On 4/08/2017 5:27 AM, Kim Barrett wrote:
>>
>> However, there are use-cases that I think are reasonable which don't
>> immediately fit that restriction.
>>
>> (1) cmpxchg(v, p, NULL), to store a pointer if no pointer is already
>> present.  This can be used as an alternative to DCLP. One way to deal
> 
> I thought NULL (aka 0 in a pointer context) was assignable to any 
> pointer type without any casts. ??

They are, but you have to distinguish between default conversions
and overload resolution.  If you have two methods

int a(foo *p);
int a(bar *p);

and you have a call

a(NULL);

the only way to resolve the overload is to do this:

a((foo*)NULL);

or this:

foo *tmp = NULL;
a(tmp);

C++ is pretty strict about this rule, because it's safer in practice
to insist that programmers say exactly what they mean than apply
conversions that might be surprising.  In several places C++ is
fussier than C.  For example, you can say this in C but not C++:

   foo *p = malloc(n);

This is a deliberate design deicison.

-- 
Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671


More information about the hotspot-dev mailing list