임베디드 개발자라면 기본적으로 알아야 할 것들을 정리한 것입니다.(출처가 생각이 안남)
후배 사원에게 한 번 풀어보라고 했는데 생각보다 점수가 잘(?) 안 나왔어요...
아주 간단하지만 아주 기초적으로 알아야 할 것들만 모았네요.
Preprocessor
1. Using the #define statement, how would you declare a manifest constant that returns the number of seconds in a year? Disregard leap years in your answer.
2. Write the "standard" MIN macro-that is, a macro that takes two arguments and returns the smaller of the two arguments.
3. What is the purpose of the preprocessor directive #error?
Infinite loops
4. Infinite loops often arise in embedded systems. How does you code an infinite loCandidates who propose this are either assembly language programmers (which is probably good), or else they are closet BASIC/FORTRAN programmers looking to get into a new field.
Data declarations
5. Using the variable a, give definitions for the following:
a) An integer
b) A pointer to an integer
c) A pointer to a pointer to an integer
d) An array of 10 integers
e) An array of 10 pointers to integers
f) A pointer to an array of 10 integers
g) A pointer to a function that takes an integer as an argument and returns an integer
h) An array of ten pointers to functions that take an integer argument and return an integer
Static
6. What are the uses of the keyword static?
Const
7. What does the keyword const mean?
What do the following declarations mean?
const int a;
int const a;
const int *a;
int * const a;
int const * a const;
Bit manipulation
8. Embedded systems always require the user to manipulate bits in registers or variables. Given an integer variable a, write two code fragments. The first should set bit 3 of a. The second should clear bit 3 of a. In both cases, the remaining bits should be unmodified.
Accessing fixed memory locations
9. Embedded systems are often characterized by requiring the programmer to access a specific memory location. On a certain project it is required to set an integer variable at the absolute address 0x67a9 to the value 0xaa55. The compiler is a pure ANSI compiler. Write code to accomplish this task.
Code examples
10. What does the following code output and why?
void foo(void)
{
unsigned int a = 6;
int b = -20;
(a+b > 6) ? puts("> 6") : puts("<= 6");
}
Typedef
11. Typedef is frequently used in C to declare synonyms for pre-existing data types. It is also possible to use the preprocessor to do something similar. For instance, consider the following code fragment:
#define dPS struct s *
typedef struct s * tPS;
The intent in both cases is to define dPS and tPS to be pointers to structure s. Which method, if any, is preferred and why?
Obscure syntax
12. C allows some appalling constructs. Is this construct legal, and if so what does this code do?
int a = 5, b = 7, c;
c = a+++b;