获取指针地址的一种令人困惑的方式 [英] a confusing way to get a pointer's address
问题描述
i对以下程序感到困惑,并且它可以获得一个
指针成员的地址。
#define NETDEV_ALIGN 32
#define NETDEV_ALIGN_CONST(NETDEV_ALIGN - 1)
static inline void * netdev_priv(struct net_device * dev)
{return(char *)dev +((sizeof(struct net_device)+
NETDEV_ALIGN_CONST)
& ~NETDEV_ALIGN_CONST);
}
Hi,
i feel confused about the following program, and it''s works to get a
pointer-member''s address.
#define NETDEV_ALIGN 32
#define NETDEV_ALIGN_CONST (NETDEV_ALIGN - 1)
static inline void *netdev_priv(struct net_device *dev)
{ return (char *)dev + ((sizeof(struct net_device)+
NETDEV_ALIGN_CONST)
& ~NETDEV_ALIGN_CONST);
}
推荐答案
On 7 2,6 6,!truth< noddy_zh ... @ asustek。 com.cnwrote:
On 7 2 , 6 56 , !truth <noddy_zh...@asustek.com.cnwrote:
i对以下程序感到困惑,并且它的作用是为了获得一个
指针成员的地址。
#define NETDEV_ALIGN 32
#define NETDEV_ALIGN_CONST(NETDEV_ALIGN - 1)
static inline void * netdev_priv(struct net_device * dev)
{return(c har *)dev +((sizeof(struct net_device)+
NETDEV_ALIGN_CONST)
& ~NETDEV_ALIGN_CONST);
}
Hi,
i feel confused about the following program, and it''s works to get a
pointer-member''s address.
#define NETDEV_ALIGN 32
#define NETDEV_ALIGN_CONST (NETDEV_ALIGN - 1)
static inline void *netdev_priv(struct net_device *dev)
{ return (char *)dev + ((sizeof(struct net_device)+
NETDEV_ALIGN_CONST)
& ~NETDEV_ALIGN_CONST);
}
对不起,我输入了错误的密钥,但没有完成我的帖子。
继续
* struct net_device *如下,你也可以参考
网页: http://www.gelato.unsw.edu.au/lxr/ source / include / linux /
netdevice.h#L260
260 struct net_device
261 {
262
263 / *
264 *这是可见字段的第一个字段。这个
结构的一部分
265 *(即用户在Space.c文件中看到的)。这是名字
266 *界面。
267 * /
268 char name [IFNAMSIZ] ;
269 / *设备名称哈希链* /
270 struct hlist_node name_hlist;
271
272 / *
273 * I / O特定字段
274 * FIXME:将这些和struct ifmap合并为一个
275 * /
276 unsigned long mem_end; / *共享内存
结束* /
277 unsigned long mem_start; / *共享内存
start * /
278 unsigned long base_addr; / *设备I / O
地址* /
279 unsigned int irq; / *设备IRQ
number * /
280
281 / *
282 *有些硬件也需要这些字段,但它们
不是
283 *是Space.c中指定的通常设置的一部分。
284 * /
285
286 unsigned char if_port; / *可选AUI,
TP,.. * /
287 unsigned char dma; / * DMA
频道* /
288
289 unsigned long state;
290
291 struct net_device * next;
292
293 / *设备初始化功能。只调用一次。
* /
294 int(* init)(struct net_device * dev);
295
296 / * -------在Space.c中预先初始化的字段在这里完成
------- * /
297
298 / *网络设备功能* /
299无符号长功能;
300 #define NETIF_F_SG 1 / * Scatter / gather IO。 * /
301 #define NETIF_F_IP_CSUM 2 / *仅校验和TCP /
UDP over IPv4。 * /
302 #define NETIF_F_NO_CSUM 4 / *不需要
校验和。 F.E. loopack。 * /
303 #define NETIF_F_HW_CSUM 8 / *可校验所有
包。 * /
304 #define NETIF_F_HIGHDMA 32 / *可以DMA到高内存。
* /
305 #define NETIF_F_FRAGLIST 64 / * Scatter /聚集IO。 * /
306 #define NETIF_F_HW_VLAN_TX 128 / *传输VLAN hw
加速* /
307 #define NETIF_F_HW_VLAN_RX 256 / *接收VLAN hw
加速* /
308 #define NETIF_F_HW_VLAN_FILTER 512 / *接收过滤
VLAN * /
309 #define NETIF_F_VLAN_CHALLENGED 1024 / *设备无法处理
VLAN数据包* /
310 #define NETIF_F_TSO 2048 / *可以卸载TCP / IP
分段* /
311 #define NETIF_F_LLTX 4096 / * LockLess TX * /
312 #define NETIF_F_UFO 8192 / *可以卸载UDP大
发送* / < br $> b $ b 313
314 struct net_device * next_sched;
315
316 / *接口索引。独特的设备标识符* /
317 int ifindex;
318 int iflink;
319
320
321 struct net_device_stats *(* get_stats)(struct net_device
* dev);
322 struct iw_statistics *(* get_wireless_stats)(struct
net_device * dev);
323
324 / *处理无线扩展的功能列表
(而不是ioctl)。
325 *详见< net / iw_handler.h。 Jean II * /
326 const struct iw_handler_def * wireless_handlers;
327 / *由无线核心管理的实例数据
扩展。 * /
328 struct iw_public_data * wireless_data;
329
330 struct ethtool_ops * ethtool_ops;
331
332 / *
333 *这标志着可见的结束
结构的一部分。所有
334 *以下的字段都是系统内部的,可能会改变
更改为
335 *会(读取:可能会在将...
336 * /
337
338
339 unsigned int flags; / *接口标志(a la
BSD)* /
340无符号短gflags;
341 unsigned short priv_flags; / *像''flags''但
对用户空间不可见。 * /
342 unsigned short padded; / *添加了多少填充
by alloc_netdev()* /
343
344 unsigned char operstate; / * RFC2863 operstate * /
345 unsigned char link_mode; / *映射政策到
operstate * /
346
347 unsigned mtu; / * interface MTU
value * /
348 unsigned short type; / *接口硬件
类型* /
349 unsigned short hard_header_len; / *
硬件硬件长度* /
350
351 struct net_device * master; / *指向掌握
组的设备,
352 *此设备是
的成员。
353 * /
354
355 / *接口地址信息。 * /
356 unsigned char perm_addr [MAX_ADDR_LEN]; / *
永久hw地址* /
357 unsigned char addr_len; / *硬件
地址长度* /
358 unsigned short dev_id; / *为共享
网卡* /
359
360 struct dev_mc_list * mc_list; / *组播mac
地址* /
361 int mc_count; / *
安装的mcasts数量* /
362 int promiscuity;
363 int allmulti;
364
365
366 / *特定于协议的指针* /
367
368 void * atalk_ptr; / * AppleTalk
link * /
369 void * ip_ptr; / * IPv4特定
数据* /
370 void * dn_ptr; / * DECnet具体
数据* /
371 void * ip6_ptr; / * IPv6特定
数据* /
372 void * ec_ptr; / * Econet具体
数据* /
373无效* ax25_ptr; / * AX.25具体
数据* /
374
375 / *
376 *缓存行大多数用于接收路径(包括
eth_type_trans())
377 * /
378 struct list_head poll_list
____cacheline_aligned_in_smp ;
379 / *民意调查清单链接* /
380
381 int(*民意调查)(struct net_device * dev,
int * quota);
382 int quota;
383 int weight;
384 unsigned long last_rx; / *最后时间
Rx * /
385 / * eth_type_trans()中使用的接口地址信息* /
386 unsigned char dev_addr [ MAX_ADDR_LEN]; / * hw
地址,(在bcast之前
387因为
大部分数据包是单播的)* /
388
389 unsigned char broadcast [MAX_ADDR_LEN]; / *
hw bcast add * /
390
391 / *
392 *缓存行主要用于队列传输路径(qdisc)
393 * /
394 / *设备队列锁定* /
395 spinlock_t queue_lock
____cacheline_aligned_in_smp;
396 struct Qdisc * qdisc;
397 struct Qdisc * qdisc_sleeping;
398 struct list_head qdisc_list;
399 unsigned long tx_queue_len; / *最大帧数每
队列允许* /
401 / *入口路径同步器* /
402 spinlock_t ingress_lock;
403 struct Qdisc * qdisc_ingress;
404
405 / *
406 *一部分主要用于xmit路径(设备)
407 * /
408 / * hard_start_xmit同步器* /
409 spinlock_t xmit_lock
____cacheline_aligned_in_smp;
410 / *处理器的cpu id输入到hard_start_xmit或-1,
411如果没有人进入那里。
412 * /
413 int xmit_lock_owner;
414 void * priv; / *私人指针
数据* /
415 int(* hard_start_xmit)(struct sk_buff
* skb,
416 struct
net_device * dev);
417 / *这些可能是未来网络断电代码所需要的。
* /
418 unsigned long trans_start; / *最后Tx的时间(在
jiffies中)* /
419
420 int watchdog_timeo; / *使用
dev_watchdog()* /
421 struct timer_list watchdog_timer;
422
423 / *
424 * refcnt是一个非常热门的点,所以在SMP上对齐
425 * /
426 / *此设备的引用数量* /
427 atomic_t refcnt
____cacheline_aligned_in_smp;
428
429 / *延迟注册/取消注册* / < br $>
430 struct list_head todo_list;
431 / *设备索引哈希链* /
432 struct hlist_node index_hlist;
433
434 / *注册/取消注册状态机* /
435 enum {NETREG_UNINITIALIZED = 0,
436 NETREG_REGISTERED,/ *已完成
register_netdevice * /
437 NETREG_UNREGISTERING,/ *调用
unregister_netdevice * /
438 NETREG_UNREGIS TERED,/ *已完成取消注册
待办事项* /
439 NETREG_RELEASED,/ *名为free_netdev * /
440} reg_state;
441
442 / *设备与网络分离后调用。 * /
443 void(* uninit)(struct net_device * dev);
444 / *在最后一个用户引用消失后调用。 * /
445无效(*析构函数)(struct net_device
* dev);
446
447 / *用于界面服务程序的指针。 * /
448 int(* open)(struct net_device * dev);
449 int(* stop)(struct net_device * dev);
450 #define HAVE_NETDEV_POLL
451 int(* hard_header)(struct sk_buff
* skb,
452 struct net_device
* dev,
453 unsigned short
类型,
454无效* daddr,
455无效* saddr,
456 unsigned len);
457 int(* rebuild_header)(struct sk_buff
* skb);
458 #define HAVE_MULTICAST
459 void(* set_multicast_list)(struct
net_device * dev);
460 #define HAVE_SET_MAC_AD DR
461 int(* set_mac_address)(struct
net_device * dev,
462 void * addr);
463 #define HAVE_PRIVATE_IOCTL
464 int(* do_ioctl)(struct net_device
* dev,
465 struct ifreq * ifr,int
cmd);
466 #define HAVE_SET_CONFIG
467 int(* set_config)(struct net_device
* dev,
468 struct ifmap * map);
469 #define HAVE_HEADER_CACHE
int int(* hard_header_cache)(struct
邻居*邻居,
471 struct
hh_cache * hh);
472 void(* header_cache_update)(struct
hh_cache * hh,
473 struct
net_device * dev,
474 unsigned
char * haddr);
475 #define HAVE_CHANGE_MTU
476 int(* change_mtu)(struct net_device
* dev,int new_mtu);
477
478 #define HAVE_TX_TIMEOUT
479无效(* tx_timeout)(struct net_device
* dev);
480
481无效( * vlan_rx_register)(struct
net_device * dev,
482 struct
vlan_group * grp);
483无效(* vlan_rx_add_vid)(struct
net_device * dev,
484 unsigned short
vid);
485无效(* vlan_rx_kill_vid)(struct
ne t_device * dev,
486 unsigned short
vid);
487
488 int(* hard_header_parse)( struct
sk_buff * skb,
489 unsigned char
* haddr);
490 int(* neigh_setup) (struct net_device
* dev,struct neigh_parms *);
491 #ifdef CONFIG_NETPOLL
492 struct netpoll_info * npinfo;
493 #endif
494 #ifdef CONFIG_NET_POLL_CONTROLLER
495 void(* poll_controller)(struct
net_device * dev);
496 #endif
497
498 / *桥接东西* /
499 struct net_bridge_port * br_port;
500
501 #ifdef CONFIG_NET_DIVERT
502 / *这将在每个接口类型初始化init
r outine * /
503 struct divert_blk * divert;
504 #endif / * CONFIG_NET_DIVERT * /
505
506 / * class / net / name entry * /
507 struct class_device class_dev;
508 / *可选统计和无线sysfs组的空间
* /
509 struct attribute_group * sysfs_groups [3];
510};
sorry, i entry a wrong key, but did not finished my thread.
go on
the *struct net_device* is as follows, also you can refer to the
webpage:http://www.gelato.unsw.edu.au/lxr/source/include/linux/
netdevice.h#L260
260 struct net_device
261 {
262
263 /*
264 * This is the first field of the "visible" part of this
structure
265 * (i.e. as seen by users in the "Space.c" file). It is
the name
266 * the interface.
267 */
268 char name[IFNAMSIZ];
269 /* device name hash chain */
270 struct hlist_node name_hlist;
271
272 /*
273 * I/O specific fields
274 * FIXME: Merge these and struct ifmap into one
275 */
276 unsigned long mem_end; /* shared mem
end */
277 unsigned long mem_start; /* shared mem
start */
278 unsigned long base_addr; /* device I/O
address */
279 unsigned int irq; /* device IRQ
number */
280
281 /*
282 * Some hardware also needs these fields, but they
are not
283 * part of the usual set specified in Space.c.
284 */
285
286 unsigned char if_port; /* Selectable AUI,
TP,..*/
287 unsigned char dma; /* DMA
channel */
288
289 unsigned long state;
290
291 struct net_device *next;
292
293 /* The device initialization function. Called only once.
*/
294 int (*init)(struct net_device *dev);
295
296 /* ------- Fields preinitialized in Space.c finish here
------- */
297
298 /* Net device features */
299 unsigned long features;
300 #define NETIF_F_SG 1 /* Scatter/gather IO. */
301 #define NETIF_F_IP_CSUM 2 /* Can checksum only TCP/
UDP over IPv4. */
302 #define NETIF_F_NO_CSUM 4 /* Does not require
checksum. F.e. loopack. */
303 #define NETIF_F_HW_CSUM 8 /* Can checksum all the
packets. */
304 #define NETIF_F_HIGHDMA 32 /* Can DMA to high memory.
*/
305 #define NETIF_F_FRAGLIST 64 /* Scatter/gather IO. */
306 #define NETIF_F_HW_VLAN_TX 128 /* Transmit VLAN hw
acceleration */
307 #define NETIF_F_HW_VLAN_RX 256 /* Receive VLAN hw
acceleration */
308 #define NETIF_F_HW_VLAN_FILTER 512 /* Receive filtering on
VLAN */
309 #define NETIF_F_VLAN_CHALLENGED 1024 /* Device cannot handle
VLAN packets */
310 #define NETIF_F_TSO 2048 /* Can offload TCP/IP
segmentation */
311 #define NETIF_F_LLTX 4096 /* LockLess TX */
312 #define NETIF_F_UFO 8192 /* Can offload UDP Large
Send*/
313
314 struct net_device *next_sched;
315
316 /* Interface index. Unique device identifier */
317 int ifindex;
318 int iflink;
319
320
321 struct net_device_stats* (*get_stats)(struct net_device
*dev);
322 struct iw_statistics* (*get_wireless_stats)(struct
net_device *dev);
323
324 /* List of functions to handle Wireless Extensions
(instead of ioctl).
325 * See <net/iw_handler.hfor details. Jean II */
326 const struct iw_handler_def * wireless_handlers;
327 /* Instance data managed by the core of Wireless
Extensions. */
328 struct iw_public_data * wireless_data;
329
330 struct ethtool_ops *ethtool_ops;
331
332 /*
333 * This marks the end of the "visible" part of the
structure. All
334 * fields hereafter are internal to the system, and may
change at
335 * will (read: may be cleaned up at will).
336 */
337
338
339 unsigned int flags; /* interface flags (a la
BSD) */
340 unsigned short gflags;
341 unsigned short priv_flags; /* Like ''flags'' but
invisible to userspace. */
342 unsigned short padded; /* How much padding added
by alloc_netdev() */
343
344 unsigned char operstate; /* RFC2863 operstate */
345 unsigned char link_mode; /* mapping policy to
operstate */
346
347 unsigned mtu; /* interface MTU
value */
348 unsigned short type; /* interface hardware
type */
349 unsigned short hard_header_len; /*
hardware hdr length */
350
351 struct net_device *master; /* Pointer to master
device of a group,
352 * which this device is
member of.
353 */
354
355 /* Interface address info. */
356 unsigned char perm_addr[MAX_ADDR_LEN]; /*
permanent hw address */
357 unsigned char addr_len; /* hardware
address length */
358 unsigned short dev_id; /* for shared
network cards */
359
360 struct dev_mc_list *mc_list; /* Multicast mac
addresses */
361 int mc_count; /* Number of
installed mcasts */
362 int promiscuity;
363 int allmulti;
364
365
366 /* Protocol specific pointers */
367
368 void *atalk_ptr; /* AppleTalk
link */
369 void *ip_ptr; /* IPv4 specific
data */
370 void *dn_ptr; /* DECnet specific
data */
371 void *ip6_ptr; /* IPv6 specific
data */
372 void *ec_ptr; /* Econet specific
data */
373 void *ax25_ptr; /* AX.25 specific
data */
374
375 /*
376 * Cache line mostly used on receive path (including
eth_type_trans())
377 */
378 struct list_head poll_list
____cacheline_aligned_in_smp;
379 /* Link to poll list */
380
381 int (*poll) (struct net_device *dev,
int *quota);
382 int quota;
383 int weight;
384 unsigned long last_rx; /* Time of last
Rx */
385 /* Interface address info used in eth_type_trans() */
386 unsigned char dev_addr[MAX_ADDR_LEN]; /* hw
address, (before bcast
387 because
most packets are unicast) */
388
389 unsigned char broadcast[MAX_ADDR_LEN]; /*
hw bcast add */
390
391 /*
392 * Cache line mostly used on queue transmit path (qdisc)
393 */
394 /* device queue lock */
395 spinlock_t queue_lock
____cacheline_aligned_in_smp;
396 struct Qdisc *qdisc;
397 struct Qdisc *qdisc_sleeping;
398 struct list_head qdisc_list;
399 unsigned long tx_queue_len; /* Max frames per
queue allowed */
400
401 /* ingress path synchronizer */
402 spinlock_t ingress_lock;
403 struct Qdisc *qdisc_ingress;
404
405 /*
406 * One part is mostly used on xmit path (device)
407 */
408 /* hard_start_xmit synchronizer */
409 spinlock_t xmit_lock
____cacheline_aligned_in_smp;
410 /* cpu id of processor entered to hard_start_xmit or -1,
411 if nobody entered there.
412 */
413 int xmit_lock_owner;
414 void *priv; /* pointer to private
data */
415 int (*hard_start_xmit) (struct sk_buff
*skb,
416 struct
net_device *dev);
417 /* These may be needed for future network-power-down code.
*/
418 unsigned long trans_start; /* Time (in
jiffies) of last Tx */
419
420 int watchdog_timeo; /* used by
dev_watchdog() */
421 struct timer_list watchdog_timer;
422
423 /*
424 * refcnt is a very hot point, so align it on SMP
425 */
426 /* Number of references to this device */
427 atomic_t refcnt
____cacheline_aligned_in_smp;
428
429 /* delayed register/unregister */
430 struct list_head todo_list;
431 /* device index hash chain */
432 struct hlist_node index_hlist;
433
434 /* register/unregister state machine */
435 enum { NETREG_UNINITIALIZED=0,
436 NETREG_REGISTERED, /* completed
register_netdevice */
437 NETREG_UNREGISTERING, /* called
unregister_netdevice */
438 NETREG_UNREGISTERED, /* completed unregister
todo */
439 NETREG_RELEASED, /* called free_netdev */
440 } reg_state;
441
442 /* Called after device is detached from network. */
443 void (*uninit)(struct net_device *dev);
444 /* Called after last user reference disappears. */
445 void (*destructor)(struct net_device
*dev);
446
447 /* Pointers to interface service routines. */
448 int (*open)(struct net_device *dev);
449 int (*stop)(struct net_device *dev);
450 #define HAVE_NETDEV_POLL
451 int (*hard_header) (struct sk_buff
*skb,
452 struct net_device
*dev,
453 unsigned short
type,
454 void *daddr,
455 void *saddr,
456 unsigned len);
457 int (*rebuild_header)(struct sk_buff
*skb);
458 #define HAVE_MULTICAST
459 void (*set_multicast_list)(struct
net_device *dev);
460 #define HAVE_SET_MAC_ADDR
461 int (*set_mac_address)(struct
net_device *dev,
462 void *addr);
463 #define HAVE_PRIVATE_IOCTL
464 int (*do_ioctl)(struct net_device
*dev,
465 struct ifreq *ifr, int
cmd);
466 #define HAVE_SET_CONFIG
467 int (*set_config)(struct net_device
*dev,
468 struct ifmap *map);
469 #define HAVE_HEADER_CACHE
470 int (*hard_header_cache)(struct
neighbour *neigh,
471 struct
hh_cache *hh);
472 void (*header_cache_update)(struct
hh_cache *hh,
473 struct
net_device *dev,
474 unsigned
char * haddr);
475 #define HAVE_CHANGE_MTU
476 int (*change_mtu)(struct net_device
*dev, int new_mtu);
477
478 #define HAVE_TX_TIMEOUT
479 void (*tx_timeout) (struct net_device
*dev);
480
481 void (*vlan_rx_register)(struct
net_device *dev,
482 struct
vlan_group *grp);
483 void (*vlan_rx_add_vid)(struct
net_device *dev,
484 unsigned short
vid);
485 void (*vlan_rx_kill_vid)(struct
net_device *dev,
486 unsigned short
vid);
487
488 int (*hard_header_parse)(struct
sk_buff *skb,
489 unsigned char
*haddr);
490 int (*neigh_setup)(struct net_device
*dev, struct neigh_parms *);
491 #ifdef CONFIG_NETPOLL
492 struct netpoll_info *npinfo;
493 #endif
494 #ifdef CONFIG_NET_POLL_CONTROLLER
495 void (*poll_controller)(struct
net_device *dev);
496 #endif
497
498 /* bridge stuff */
499 struct net_bridge_port *br_port;
500
501 #ifdef CONFIG_NET_DIVERT
502 /* this will get initialized at each interface type init
routine */
503 struct divert_blk *divert;
504 #endif /* CONFIG_NET_DIVERT */
505
506 /* class/net/name entry */
507 struct class_device class_dev;
508 /* space for optional statistics and wireless sysfs groups
*/
509 struct attribute_group *sysfs_groups[3];
510 };
继续
我的问题是
1.函数是获取结构中* priv *的地址
$ b $ 341 net_device在第341行,但它是如何做到的?
2.what'是* NETDEV_ALIGN_CONST *用于什么?
3.为什么不这样做:
struct net_device * dev;
void * tp;
/ * alloc记忆* /
tp = dev-> priv
而不是
void * tp = netdev_priv(dev)
谢谢。
continue
my question is
1. the function is to get the address of *priv* in the structure
net_device at line 341, but how it can do that?
2.what''s the *NETDEV_ALIGN_CONST* used for?
3.why not to do as follows:
struct net_device *dev;
void *tp;
/*alloc memory*/
tp=dev->priv
instead of
void *tp=netdev_priv(dev)
thanks.
开2月2日,12:06,真相< noddy_zh ... @ asustek.com.cn写道:
On 2 Jul, 12:06, !truth <noddy_zh...@asustek.com.cnwrote:
继续
我的问题是
1.函数是在结构中获取* priv *的地址
net_device在第341行,...
continue
my question is
1. the function is to get the address of *priv* in the structure
net_device at line 341,...
不,它不是......它与私人有关我认为,第414行的字段。
No it isn''t... It relates to the "priv" field at line 414, I think.
2.what'是* NETDEV_ALIGN_CONST *用于?
2.what''s the *NETDEV_ALIGN_CONST* used for?
这是一种强制特定数据对齐的技术。
It''s a technique to force specific alignment of data.
3.为什么不这样做如下:
struct net_device * dev;
void * tp;
/ * alloc memory * /
tp = dev-> priv
而不是
void * tp = netdev_priv(dev)
3.why not to do as follows:
struct net_device *dev;
void *tp;
/*alloc memory*/
tp=dev->priv
instead of
void *tp=netdev_priv(dev)
我不知道 - 但是大概这个代码的开发人员有一个很好的原因。我从快速扫描的猜测是代码的设计
知道那个私人 netdev结构的数据总是在netdev结构之后立即放入内存中,与32字节的
通过指针算法获取其地址而不是通过内存访问...
I认为你在询问Linux内核设计问题,而不是在这里询问
pure C.快速Google fornetdev_priv显示在公开可见的邮件列表中讨论过这个问题。
如果您正在检查Linux源代码,您可能会发现
comp.os.linux.development.system和/或其中一个邮件列表比一般的C新闻组更有用。
I don''t _know_ - but presumably the developers of this code had a good
reason. My guess from a quick scan is that the design of the code
"knows" that the "private" data for a netdev structure is always put
in memory immediately after the netdev structure, aligned to a 32-byte
boundary. It''s therefore quicker (and this is probably heavily used)
to get its address by pointer arithmetic than by a memory access...
I think you are asking about Linux kernel design issues rather than
pure C here. A quick Google for "netdev_priv" shows that this has been
discussed in publicly visible mailing lists.
If you are examining Linux sources, you may find
comp.os.linux.development.system and/or one of the mailing lists more
useful than a general C newsgroup.
这篇关于获取指针地址的一种令人困惑的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!