What does '_IO(…)' mean in C headers in Linux?

白昼怎懂夜的黑 提交于 2019-12-01 03:32:45

They define ioctl numbers, based on ioctl function and input parameters. The are defined in kernel, in include/asm-generic/ioctl.h.

You need to include <linux/ioctl.h> (or linux/asm-generic/ioctl.h) in your program. Before including
/usr/src/linux-headers-3.2.0-35/include/linux/usbdevice_fs.h

You can't "precompile" this values (e.g. USBDEVFS_DISCARDURB), because they can be different on other platforms. For example, you are developing your code on plain old x86, but then someone will try to use it on x86_64/arm/mips/etc. So you should always include kernel's ioctl.h to make sure, you are using right values.

These are also macros defined elsewhere.

In general if you want to see your code after pre-processor has been computed use

gcc -E foo.c

this will output your code pre-processed

For example:

foo.c

#define FORTY_TWO 42

int main(void)
{
  int foo = FORTY_TWO;
}

will give you with gcc -E foo.c:

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