Oh, very cool. I had not yet stumbled upon it. This is definitly better
than my solution, as it most likely won't generate any code where it's not
needed.
Just an hour ago I wrote my own little hacky thing: a simple asm function
that returns its first parameter.
extern "C" {
myT *refPtr( myT & );
};
As the asm simply does
mov rax, rcx
ret
Works fine as we know under the hood references are pointers. I would hope
the CPU itself would optimize around the call-ret, seeing only one uOp
being produced before reaching the "ret".
Am Donnerstag, 5. September 2019 00:43:18 UTC+2 schrieb Kenton Varda:
>
> Hi Stefan,
>
> A Builder already acts like a pointer: You can copy it by value, and the
> copy manipulates the same underlying message.
>
> If you just want to express the type "capnp::Builder or null", then I
> suggest using `kj::Maybe<capnp::Builder>`, which serves exactly this
> purpose. A `kj::Maybe<T>` can be assigned to any `T` or to `nullptr`. You
> can unpack a Maybe with `KJ_IF_MAYBE()`. Check out the comments in
> `kj/commen.h` and copious examples throughout the KJ and Cap'n Proto source
> code to learn more.
>
> -Kenton
>
> On Wed, Sep 4, 2019 at 11:10 AM Stefan Kaps <[email protected]
> <javascript:>> wrote:
>
>> Hi,
>>
>> i would like to use pointers to builders in my exporter, so I can pass
>> nullptr in case of "please simply do a check, but do not build
>> capnp-data". Is this possible at all?
>>
>> If not, are there any suggestions you have for me how to provide such
>> functionality?
>>
>> Thanks a lot in advance,
>> Stefan
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Cap'n Proto" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/capnproto/c4c89dfb-6700-406e-99bf-e5c01c89fddf%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/capnproto/c4c89dfb-6700-406e-99bf-e5c01c89fddf%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/capnproto/97f32335-e03f-45ba-8125-12a121af6df8%40googlegroups.com.