Skip to content

Instantly share code, notes, and snippets.

@hkdnet
Last active August 10, 2018 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkdnet/0176340f10b71ef2a7262e2680645e5d to your computer and use it in GitHub Desktop.
Save hkdnet/0176340f10b71ef2a7262e2680645e5d to your computer and use it in GitHub Desktop.
union の deconst 外すやつ
diff --git a/iseq.c b/iseq.c
index 997dd7f1f7..be9efb9aad 100644
--- a/iseq.c
+++ b/iseq.c
@@ -989,11 +989,8 @@ static const rb_data_type_t iseqw_data_type = {
static VALUE
iseqw_new(const rb_iseq_t *iseq)
{
- union { const rb_iseq_t *in; void *out; } deconst;
VALUE obj;
-
- deconst.in = iseq;
- obj = TypedData_Wrap_Struct(rb_cISeq, &iseqw_data_type, deconst.out);
+ obj = TypedData_Wrap_Struct(rb_cISeq, &iseqw_data_type, (void *)iseq);
RB_OBJ_WRITTEN(obj, Qundef, iseq);
return obj;
int bar(void* b) {
return 1;
}
void tekitou(char* a)
{
bar((void *)a);
}
int main(int argc, char const* argv[])
{
tekitou("aiueo");
return 0;
}
$ clang -Wcast-qual foo.c -o foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment