Why does DIRECT_RW macro look as it does?

23 views
Skip to first unread message

Jan K

unread,
Aug 2, 2018, 6:56:02 AM8/2/18
to pmem
Hello,

Browsing the code, I noticed that D_RW macro (for compilers other than microsoft visual) is defined as:
#define DIRECT_RW(o) (\
{__typeof__(o) _o; _o._type = NULL; (void)_o;\
(__typeof__(*(o)._type) *)pmemobj_direct((o).oid); })

While D_RO is just:
#define DIRECT_RO(o) ((const __typeof__(*(o)._type) *)pmemobj_direct((o).oid))

Now my question is: what is the purpose of the part: __typeof__(o) _o; _o._type = NULL; (void)_o; in D_RW macro?
Would it not be just be always optimized out?

What would go wrong if D_RW were implemented just as:
#define DIRECT_RW(o) ((__typeof__(*(o)._type) *)pmemobj_direct((o).oid))

thus avoiding non-standard ({ … }) syntax and seemingly redundant statements?

Plus: do apps with no optimization (-O0) create the _o and execute the assignment _o._type = NULL?

Link to github:

Regards,
Jan

Piotr Balcer

unread,
Aug 2, 2018, 8:22:43 AM8/2/18
to pmem
Hi,
It there so that you can't D_RW on a const TOID.
And yes, it does have some impact on non-optimized assembly.

Piotr

OpenData Synth

unread,
Sep 1, 2018, 4:07:20 PM9/1/18
to pmem
Yes
Reply all
Reply to author
Forward
0 new messages