[前][次][番号順一覧][スレッド一覧]

ruby-changes:63090

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Fri, 25 Sep 2020 11:39:00 +0900 (JST)
Subject: [ruby-changes:63090] c6c241e49c (master): enrich comment

https://git.ruby-lang.org/ruby.git/commit/?id=c6c241e49c

From c6c241e49c35a2bf0079499459f60f470f97395a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Fri, 25 Sep 2020 10:21:45 +0900
Subject: enrich comment

Added description and URL about nested flexible array member.

diff --git a/include/ruby/internal/stdalign.h b/include/ruby/internal/stdalign.h
index 2bd8d94..122f649 100644
--- a/include/ruby/internal/stdalign.h
+++ b/include/ruby/internal/stdalign.h
@@ -112,10 +112,19 @@ struct rbimpl_alignof { https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/stdalign.h#L112
 # define RBIMPL_ALIGNOF __alignof
 
 #else
-# /* :BEWARE: It is  an undefined behaviour to define a  struct/union inside of
-#  * `offsetof()`!  This section is the  last resort.  If your compiler somehow
-#  * supports querying  alignment of a type  please add your own  definition of
-#  * `RBIMPL_ALIGNOF` instead. */
+# /* :BEWARE:  This is  the last  resort.   If your  compiler somehow  supports
+#  * querying the alignment of a type,  you definitely should use that instead.
+#  * There are 2 known pitfalls for this fallback implementation:
+#  *
+#  * Fitst, it is either an undefined  behaviour (C) or an explicit error (C++)
+#  * to define a  struct inside of `offsetof`. C compilers  tend to accept such
+#  * things, but AFAIK C++ has no room to allow.
+#  *
+#  * Second, there exist T  such that `struct { char _; T t;  }` is invalid.  A
+#  * known example is  when T is a  struct with a flexible  array member.  Such
+#  * struct cannot be enclosed into another one.
+#  */
+# /* see: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2083.htm */
 # /* see: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm */
 # define RBIMPL_ALIGNOF(T) offsetof(struct { char _; T t; }, t)
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]