What Is The Meaning of This Macro _Ior(My_Macig, 0, Int)

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

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.

/proc filesystem advantages

You should see /proc as a pipe to kernel. You can modify kernel parameters and see what kernel is doing at a moment in time.

Regards

Macro definition to determine big endian or little endian machine?

Code supporting arbitrary byte orders, ready to be put into a file called order32.h:

#ifndef ORDER32_H
#define ORDER32_H

#include <limits.h>
#include <stdint.h>

#if CHAR_BIT != 8
#error "unsupported char size"
#endif

enum
{
O32_LITTLE_ENDIAN = 0x03020100ul,
O32_BIG_ENDIAN = 0x00010203ul,
O32_PDP_ENDIAN = 0x01000302ul, /* DEC PDP-11 (aka ENDIAN_LITTLE_WORD) */
O32_HONEYWELL_ENDIAN = 0x02030001ul /* Honeywell 316 (aka ENDIAN_BIG_WORD) */
};

static const union { unsigned char bytes[4]; uint32_t value; } o32_host_order =
{ { 0, 1, 2, 3 } };

#define O32_HOST_ORDER (o32_host_order.value)

#endif

You would check for little endian systems via

O32_HOST_ORDER == O32_LITTLE_ENDIAN

What is the meaning of the using guard macro in struct definition

You are right that there is no change in the behavior of the code.
There is no apparent benefit from the code you show.

This is because

#define GS

Defines GS as nothing, so after the preprocessor finishes, there is no difference from not including it in the declaration of the struct.

struct gs {

What could be the reason would be if there is some other tool that reads the code before the preprocessor and marks some kind of usage.

Note: in the comments, you reference other code. That code may, depending on other flags, set the macro to something, such as BOOST_SYMBOL_EXPORT. That then may have specific meaning. These kinds of usage are often used for marking classes as export or import depending on what the compiler is doing at the time.



Related Topics



Leave a reply



Submit