Re: target_core_user.h in C++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2015-10-13 11:33, Bart Van Assche wrote:
On 10/13/2015 11:28 AM, Oleg Smolsky wrote:
-enum tcmu_opcode {
+enum tcmu_opcode
+#if defined(__cplusplus)
+        : __u32
+#endif
+{

Will this work with older C++ compilers ?

No, this is a C++11 thing. I've added an extra check.

  static inline enum tcmu_opcode tcmu_hdr_get_op(__u32 len_op)
  {
-       return len_op & TCMU_OP_MASK;
+        __u32 rv = len_op & TCMU_OP_MASK;
+#if defined(__cplusplus)
+        return tcmu_opcode(rv);
+#else
+        return rv;
+#endif
  }

How about using (enum tcmu_opcode)rv for C and C++ instead of the #ifdef construct ?
Sure, the cast works too.

Oleg.

diff --git a/include/uapi/linux/target_core_user.h b/include/uapi/linux/target_core_user.h
index 95c6521..52ab6fa 100644
--- a/include/uapi/linux/target_core_user.h
+++ b/include/uapi/linux/target_core_user.h
@@ -55,7 +55,11 @@ struct tcmu_mailbox {

 } __packed;

-enum tcmu_opcode {
+enum tcmu_opcode
+#if defined(__cplusplus) && __cplusplus >= 201103L
+        : __u32
+#endif
+{
        TCMU_OP_PAD = 0,
        TCMU_OP_CMD,
 };
@@ -76,7 +80,8 @@ struct tcmu_cmd_entry_hdr {

 static inline enum tcmu_opcode tcmu_hdr_get_op(__u32 len_op)
 {
-       return len_op & TCMU_OP_MASK;
+ return (tcmu_opcode)(len_op & TCMU_OP_MASK); // note, an explicit conversion is needed
+                                                     // in C++11 and higher
 }

 static inline void tcmu_hdr_set_op(__u32 *len_op, enum tcmu_opcode op)


--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux SCSI]     [Kernel Newbies]     [Linux SCSI Target Infrastructure]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Device Mapper]

  Powered by Linux