c, function definition following struct

落爺英雄遲暮 提交于 2019-12-01 21:52:59

问题


  675  * Check the validity of an ACL for a file.
  676  */
  677 int
  678 ufs_aclcheck(ap)
  679         struct vop_aclcheck_args /* {
  680                 struct vnode *vp;
  681                 acl_type_t type;
  682                 struct acl *aclp;
  683                 struct ucred *cred;
  684                 struct thread *td;
  685         } */ *ap;
  686 {
  687 
  688         if ((ap->a_vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS)) == 0)
  689                 return (EOPNOTSUPP);
  690 
  691         if (ap->a_type == ACL_TYPE_NFS4)
  692                 return (ufs_aclcheck_nfs4(ap));
  693 
  694         return (ufs_aclcheck_posix1e(ap));
  695 }
  696 
  697 #endif /* !UFS_ACL */

This code comes from Freebsd UFS source. This function looks strange. After function name, there is a struct being defined. What's the deal? thanks


回答1:


This is an old style of writing C functions where you could define a function like:

void foo(a)  /* Function and its arguments */
   int a; /* Define the type of the arguments */
{
  // Function body
}

What you have in your function, after removing the comments:

int ufs_aclcheck(ap)
    struct vop_aclcheck_args * ap;
{
   // Function body
}


来源:https://stackoverflow.com/questions/22993255/c-function-definition-following-struct

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!