macro in gtk

本文详细解析了GTK_WINDOW宏的工作原理及内部实现机制。通过层层展开GTK_WINDOW宏定义,揭示其如何进行类型检查并完成对象转换的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GTK_WINDOW is a macro that does the cast.

As seen here

#define GTK_WINDOW(obj)  (GTK_CHECK_CAST ((obj), GTK_TYPE_WINDOW, GtkWindow))

Again

#define GTK_CHECK_CAST G_TYPE_CHECK_INSTANCE_CAST

and

#define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) (_G_TYPE_CIC ((instance), (g_type), c_type))

which is...

#define _G_TYPE_CIC(ip,gt,ct)    \
    ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))

The code for g_type_check_instance_cast can be found here

GTypeInstance*
g_type_check_instance_cast (GTypeInstance *type_instance,
                            GType          iface_type)
{
  if (type_instance)
    {
      if (type_instance->g_class)
        {
          TypeNode *node, *iface;
          gboolean is_instantiatable, check;

          node = lookup_type_node_I (type_instance->g_class->g_type);
          is_instantiatable = node && node->is_instantiatable;
          iface = lookup_type_node_I (iface_type);
          check = is_instantiatable && iface && type_node_conforms_to_U (node, iface, TRUE, FALSE);
          if (check)
            return type_instance;

          if (is_instantiatable)
            g_warning ("invalid cast from `%s' to `%s'",
                       type_descriptive_name_I (type_instance->g_class->g_type),
                       type_descriptive_name_I (iface_type));
          else
            g_warning ("invalid uninstantiatable type `%s' in cast to `%s'",
                       type_descriptive_name_I (type_instance->g_class->g_type),
                       type_descriptive_name_I (iface_type));
        }
      else
        g_warning ("invalid unclassed pointer in cast to `%s'",
                   type_descriptive_name_I (iface_type));
    }

  return type_instance;
}
share | edit | flag
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值