Re: target_core_user.h in C++

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

 



On 2015-10-13 11:47, Bart Van Assche wrote:
On 10/13/2015 11:41 AM, Oleg Smolsky wrote:
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
+{

Hello Oleg,

As far as I know the tcmu_opcode enum type is not used anywhere as a member of a struct. So why is the explicit size specification needed ?

Hey Bart, my understanding of "enum" is that the compiler chooses a representation that is wide enough to support the set of present values. The code only cares about the bottom 3 bits, yet that is not stated anywhere to the compiler (and the mask can change in the future).

So, I'd explicitly state that you need a byte/uint16/uint32 - that's what the feature is for. You can choose any standard type there for now.

   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
   }

C compilers will report a syntax error for the above code. Please reread my previous e-mail.
Oh, right, C needs the "enum". Yet you do not need two statements though:

@@ -76,7 +80,9 @@ struct tcmu_cmd_entry_hdr {

 static inline enum tcmu_opcode tcmu_hdr_get_op(__u32 len_op)
 {
-       return len_op & TCMU_OP_MASK;
+ return (enum 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)


Kind regards,
Oleg.
--
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