새내기 리눅스 매니아.질문.

iimec2의 이미지

19. define문이

 #define BUG()   __bug(__FILE__, __LINE__ , NULL); 

되어 있고..

같은 소스 코드안에

extern void __bug (const char *fiel, int line , void *data);

라는 함수 가 있을 시

BUG()를 호출하면 디파인 문에 정의된 것이 실행될텐데..
extern void __bug 함수하고는 별게 인가요?
아님 이 함수를 호출 하게 되나요ㅕ?

두번째 질문은요?

질문.

struct driver {
	const char *name;

	void *(*probe)(
	    struct device *dev,		/* the device */
	    unsigned intf,			/* what interface */
	    const struct device_id *id	/* from id_table */
	    );
	void (*disconnect)(struct device *, void *);

	struct list_head driver_list;

	struct file_operations *fops;
	int minor;

	struct semaphore serialize;

	/* ioctl -- userspace apps can talk to drivers through usbdevfs */
	int (*ioctl)(struct usb_device *dev, unsigned int code, void *buf);

	/* support for "new-style" USB hotplugging
	 * binding policy can be driven from user mode too
	 */
	const struct device_id *id_table;

	/* suspend before the bus suspends;
	 * disconnect or resume when the bus resumes */
	// void (*suspend)(struct usb_device *dev);
	// void (*resume)(struct usb_device *dev);
};

위와 같은 구조체가 있는데.

static struct driver hub_driver = {
	name:		"hub",
	probe:		hub_probe,
	ioctl:		hub_ioctl,
	disconnect:	hub_disconnect,
	id_table:	hub_id_table,
};

으로 선언 할 수 있는 거여요???

소리의 이미지

iimec2 wrote:
19. define문이
 #define BUG()   __bug(__FILE__, __LINE__ , NULL); 

되어 있고..

같은 소스 코드안에

extern void __bug (const char *fiel, int line , void *data);

라는 함수 가 있을 시

BUG()를 호출하면 디파인 문에 정의된 것이 실행될텐데..
extern void __bug 함수하고는 별게 인가요?
아님 이 함수를 호출 하게 되나요ㅕ?

BUG()를 호출하시는 것은 __bug(__FILE__, __LINE__, NULL);을 호출하시는 것과 완전히 같습니다. 즉 extern 지시자와 함께 선언하신 __bug()가 호출됩니다.

iimec2 wrote:
두번째 질문은요?

질문.

struct driver {
	const char *name;

	void *(*probe)(
	    struct device *dev,		/* the device */
	    unsigned intf,			/* what interface */
	    const struct device_id *id	/* from id_table */
	    );
	void (*disconnect)(struct device *, void *);

	struct list_head driver_list;

	struct file_operations *fops;
	int minor;

	struct semaphore serialize;

	/* ioctl -- userspace apps can talk to drivers through usbdevfs */
	int (*ioctl)(struct usb_device *dev, unsigned int code, void *buf);

	/* support for "new-style" USB hotplugging
	 * binding policy can be driven from user mode too
	 */
	const struct device_id *id_table;

	/* suspend before the bus suspends;
	 * disconnect or resume when the bus resumes */
	// void (*suspend)(struct usb_device *dev);
	// void (*resume)(struct usb_device *dev);
};

위와 같은 구조체가 있는데.

static struct driver hub_driver = {
	name:		"hub",
	probe:		hub_probe,
	ioctl:		hub_ioctl,
	disconnect:	hub_disconnect,
	id_table:	hub_id_table,
};

으로 선언 할 수 있는 거여요???

원하시는 건 다음과 같이 하셔야 바릅니다.

static struct driver hub_driver = {
	.name = "hub",
	.probe = hub_probe,
	.ioctl = hub_ioctl,
	.disconnect = hub_disconnect,
	.id_table = hub_id_table
};

단, 이것은 C99에서만 가능하며 그 이전의 표준에는 존재하지 않는 구조체 생성 방식입니다.

doldori의 이미지

iimec2 wrote:
static struct driver hub_driver = {
	name:		"hub",
	probe:		hub_probe,
	ioctl:		hub_ioctl,
	disconnect:	hub_disconnect,
	id_table:	hub_id_table,
};

으로 선언 할 수 있는 거여요???

소리님의 답변에 부연하여 말씀드리면 이러한 구조체의 초기화 방식은 gcc의 확장
기능(Designated Initializers)으로 지원되는 것입니다. 현재는 obsolete feature이지만요.