Today, the boss asked me to give some embedded interview questions to an interviewer, mainly to learn more about his technology. I have encountered the following problems, and each problem is behind the fact that an embedded programmer should have the relevant skills. Of course, these are my personal understandings and are not necessarily correct. I would like to share with you the hope that my friends can get a little inspiration: how to seize every opportunity to show your uniqueness?
Many people may be able to answer the same technical question correctly, but some people only know it, but do not know it. In fact, there is usually a hidden research point behind every question of the interviewer. If we can see the essence behind the question and use the opportunity to answer the answer, I believe that the difference between the 90 and 100 points will come out. Which interviewer does not like to hire an employee who is fond of thinking and can see the essence of the phenomenon ~
Next, let's take a look at the xuanjicang behind the Embedded C interview questions ~. Here are some of my personal ideas. You are welcome to discuss them ~~
////////////////////////////
1. int A = 2, B = 11, c = a + B ++/A ++; what is the C value?
[Test Site] encoding specifications.
On the surface, it's hard to remember the priority of operators? Isn't it the order in which operators are combined? So how can we avoid it? C = a + (B ++)/(A ++) Isn't that all right? In fact, what's behind the problem is how your coding specifications and How to Write clear and easy-to-understand code, in a team, how can we make your code easy for new users to understand without any deviation ~
2. What is the difference between static variables used in global variable definitions and local variable definitions in functions?
[Test Site] Coding specifications and modular design.
The two attributes of the static variable involve the storage location and the visible domain. In large-scale program design, static global variables can effectively avoid repeated namespaces and unintentional variable references. This can effectively improve the security of program design, while also using modular jobs.
3. Where do I need to use define in programming? How to Use define to define the number of hours of constants within a year?
Test site portability.
Embedded program design features software and hardware platform variability. the effective use of the define constant can improve the portability of the program, which is convenient and error-free.
4. What are the differences between define macro statements and inline functions?
[Test Site] space-time efficiency and macro side effects.
Embedded system platforms usually have limited storage resources, but at the same time have certain requirements on real-time performance. How to weigh the two needs to be considered. Compared with function calls, define macro statements can improve the running time performance, but consume space. Moreover, nonstandard macro statements are more prone to side effects in non-standard coding, therefore, the inline function is a perfect substitute for define statements. It is the ultimate goal of embedded systems to make small funds do things!
5. Where can I use const? What are the functions of using const to modify const variables and function input parameters?
Test site: program design reliability.
The const read-only variable can effectively overcome some drawbacks of the define constant, such as non-type security check. Const parameters can effectively avoid unintentional changes within the program. People are not sages, so we need to hand over all these possible mistakes to the smart compiler, so that the errors can be killed in the cradle.
6. How many bytes does int, short, and char occupy on 32-bit platforms? Each struct contains one int, short, and char variable. What is the total memory space occupied by the struct?
Test site: port data across platforms.
Embedded systems are not x86, and their hardware platforms are quite different. The same as int systems may occupy different bytes in different architectures. Different platforms also have different compilers, which may have different characteristics in variable alignment. Therefore, how to design the sequence of member variables to effectively reduce the occupied memory space and how to fill in specific fields to ensure access alignment during struct definition, they are all cross-platform portability issues that should be considered during the design of embedded system structures.
7. How to define an unsigned int as a 32-bit type? What is the difference between define and typedef?
Test site: port data across platforms.
Both define and typedef can implement variable type redefinition, but pointer variables of the typedef type can effectively remove the ambiguity of variable definition. In embedded engineering projects, a header file of the data type is usually defined separately to ensure the unification of data types and facilitate cross-platform migration, type Def of all data types used into a familiar form
8. Have you used volatile? What are the typical application scenarios?
[Test Site] side effects of compilation optimization.
Generally, to improve the program running efficiency, the compiler automatically performs some optimizations, such as placing variables in registers to reduce the number of memory accesses and not re-reading the memory when the data remains unchanged for a long time. However, optimization may sometimes cause problems, such as hardware registers, multi-task shared variables, interruptions, and master program shared variables. Optimization may result in Inconsistent Data Access. Therefore, for these individual variables, we need to use the volatile statement to tell the compiler to cancel optimization.
9. What are the parameters transmitted? What are the advantages and disadvantages of register and stack transfer?
[Test Site] compilation optimization, call performance, and interface design.
Each architecture and the corresponding compiler have their own rules for parameter passing. Parameter transfer is not always carried out through the stack. It takes time to input and output parameters to the stack. The Compiler always tries its best to use registers to transmit parameters because the register access efficiency is high, however, when there are too many parameters, optimization will be abandoned and parameters will be passed through the stack. Therefore, to improve the call performance, we should minimize the number of parameters. If there are too many parameters, we can redefine all parameters as a struct and use struct pointers to pass parameters. The features of the hardware platform and compiler should be taken into account when designing function interfaces, and parameters should be flexibly defined.
10. What should I pay attention to when designing interrupted service programs? How can I select an interrupt trigger? What if the interrupt processing is too long? How does the interrupt handler interact with the master application?
[Test Site] interrupt service program design.
The biggest feature of embedded programs is that they often need to deal with hardware. interruption is a typical method of receiving external input, which usually determines the system operation process, therefore, how to deal with interruptions efficiently without loss is an issue that every embedded programmer should consider.
11. How are TCP/IP and OSI Layer-7 models divided? What are the advantages of this design for the functions of each layer?
[Test Site] hierarchical software design ensures portability.
The biggest benefit of a layered model is that a layer changes. As long as the interface provided by the upper layer is not changed, the upper layer does not need to be changed. Therefore, you only need to change the implementation of this layer. Because of the software and hardware variability of the embedded platform, in order to maximize the use of previous achievements, software design must follow this hierarchical model to ensure its portability.
12. What is the difference between TCP and UDP? Which layer does network interconnection devices use? How to create a link? How to Implement congestion control?
[Test Site] protocol design reliability and buffer zone design management.
The biggest difference between TCP and UDP is reliability. TCP establishes or releases connections securely and reliably through the three-way handshake protocol and timeout mechanism. The biggest problem in protocol design is how to ensure efficiency and reliability. The design of TCP provides a reference for us. The sliding window mechanism can effectively control the congestion, but the design of the window size is related to problems such as memory utilization and buffer efficiency reliability. In the embedded driver design, the buffer zone is often used for traffic control and data coverage prevention. The buffer size design requires more specific application design to ensure reliability and flexibility.