免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2372 | 回复: 4
打印 上一主题 下一主题

[内核入门] linux的C源码里的this指针是什么意思? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-06-14 15:44 |只看该作者 |倒序浏览
本帖最后由 testh 于 2012-06-14 15:47 编辑

虽然没有实际用C++写过东西,但是对知道C++中有个this指针,原意为指向类自身的指针。
但是我在跟踪mount源码的时候,看到了如下的代码:

  1. /*
  2. * Name resolution.
  3. * This is the basic name resolution function, turning a pathname into
  4. * the final dentry. We expect 'base' to be positive and a directory.
  5. *
  6. * Returns 0 and nd will have valid dentry and mnt on success.
  7. * Returns error and drops reference to input namei data on failure.
  8. */
  9. static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
  10. {
  11.         struct path next;
  12.         struct inode *inode;
  13.         int err;
  14.         unsigned int lookup_flags = nd->flags;
  15.        
  16.         while (*name=='/')
  17.                 name++;
  18.         if (!*name)
  19.                 goto return_reval;

  20.         inode = nd->dentry->d_inode;
  21.         if (nd->depth)
  22.                 lookup_flags = LOOKUP_FOLLOW;

  23.         /* At this point we know we have a real path component. */
  24.         for(;;) {
  25.                 unsigned long hash;
  26.                 struct qstr this;
  27.                 unsigned int c;

  28.                 err = exec_permission_lite(inode, nd);
  29.                 if (err == -EAGAIN) {
  30.                         err = permission(inode, MAY_EXEC, nd);
  31.                 }
  32.                 if (err)
  33.                         break;

  34.                 this.name = name;                             //////<<==========这里也有一个this
  35.                 c = *(const unsigned char *)name;

  36.                 hash = init_name_hash();
  37.                 do {
  38.                         name++;
  39.                         hash = partial_name_hash(c, hash);
  40.                         c = *(const unsigned char *)name;
  41.                 } while (c && (c != '/'));
  42.                 this.len = name - (const char *) this.name;
  43.                 this.hash = end_name_hash(hash);
复制代码
this.name=name;
想请教下熟悉的朋友,这种用法的含义是否与C++语法中的this一致,如果一致的话,那这个this又指向谁呢?
文件路径linux2.6.16/fs/Namei.c

论坛徽章:
0
2 [报告]
发表于 2012-06-14 16:10 |只看该作者
看看28行。lol

论坛徽章:
0
3 [报告]
发表于 2012-06-14 16:16 |只看该作者
28.                struct qstr this;

只是个普通的结构体

论坛徽章:
0
4 [报告]
发表于 2012-06-14 17:55 |只看该作者
fuck..fuck...fuck......all the time
3ks

论坛徽章:
0
5 [报告]
发表于 2012-06-18 13:58 |只看该作者
lollol
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP