First, let's talk about array assignment. Well, in C language, array assignment and structure assignment are very simple, just use = and memcpy operations.
Reference address:The profoundness of C language: assignment operations of arrays and structures
But recently, when I was looking at the kernel implementation code for queue scheduling, I found the following strange assignment statement. (For the specific program, see line 539 of linux-2.6.8:net/core/Rtnetlink.c)
- #define RTM_MAX (RTM_BASE+47)
- #define RTM_GETLINK (RTM_BASE+2)
- struct rtnetlink_link
- {
- int (*doit)(struct sk_buff *, struct nlmsghdr*, void *attr);
- int (*dumpit)(struct sk_buff *, struct netlink_callback *cb);
- };
- static struct rtnetlink_link link_rtnetlink_table[RTM_MAX-RTM_BASE+1] =
- //RTM_MAX-RTM_BASE+1=48
- {
- [RTM_GETLINK - RTM_BASE] = { .dumpit = rtnetlink_dump_ifinfo },
- [RTM_SETLINK - RTM_BASE] = { .doit = do_setlink },
- [RTM_GETADDR - RTM_BASE] = { .dumpit = rtnetlink_dump_all },
- [RTM_GETROUTE - RTM_BASE] = { .dumpit = rtnetlink_dump_all },
- [RTM_NEWNEIGH - RTM_BASE] = { .doit = neigh_add },
- [RTM_DELNEIGH - RTM_BASE] = { .doit = neigh_delete },
- [RTM_GETNEIGH - RTM_BASE] = { .dumpit = neigh_dump_info }
- };
This is the first time I have seen the assignment statement above. After reading it for a long time, I finally understood the meaning of this assignment statement. It turns out that C language can also assign values in this way.
Note: There are two things to note about the above assignment statement.
1, [RTM_GETLINK - RTM_BASE] = { .dumpit = rtnetlink_dump_ifinfo }, This indicates that when assigning values to an array, the C language can assign values to the element in question. In this example, it is equal to [2] = {...}, which means assigning values to the second element.
2. { .dumpit = rtnetlink_dump_ifinfo } indicates that, in the structure assignment, a specific structure member can also be assigned separately.
Previous article:Understanding the topology of high voltage power supply (1)
Next article:Content and number of bits of a TCP/IP frame
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
Guess you like
- GCC GD32E230 toolchain startup and linking files
- Semiconductor Recruitment-Shanghai, Shenzhen, Hangzhou
- Four major reasons for the heating of power modules
- LCR parallel resonance
- How to implement the 0-10V circuit of the inverter and motor speed control interface?
- BLE over-the-air upgrade
- Module Power Structure Design Guide
- MSP430G2755 Main Bootloader UART Porting Guide
- Zibee transparent transmission program development
- World clock controlled by NXP LPC845