memset函数参数问题

0 views
Skip to first unread message

hc huang

unread,
Jul 21, 2008, 8:40:55 PM7/21/08
to linuxe...@googlegroups.com
下面是初始化cdev中的一小段代码,但是发现一个有关memset参数的问题:
void cdev_init(struct cdev *cdev,struct file_operations *fops)
{
    memset(cdev,0,sizeof *cdev);//对字符设备进行清零操作
    /*
这是memset函数的源代码
void  memset(void* s, int c, size_t n)
 {
         int i;
         char *ss = (char*)s;
         for (i=0;i<n;i++) ss[i] = c;
 }
 */
在memset函数中,发现参数s是指向空的指针,但是在上面标注红颜色的使用中,cdev参数并不是指向空的成员,
这样的使用为什么能够正常使用,而不出现问题呢?

wu gang

unread,
Jul 21, 2008, 9:22:16 PM7/21/08
to linuxe...@googlegroups.com


2008/7/22 hc huang <china...@gmail.com>:


  空指针在实际的作用还是很多的,具体参考以下:







--
学习是平淡的,又是充满激情的。just do it
my blog:http://blog.chinaunix.net/u1/55599/
Reply all
Reply to author
Forward
0 new messages