C Language Issues in Embedded Development

Use the preprocessor directive #define to declare a constant that indicates how many seconds are in a year (ignoring leap years):

#define  SECONDS_PER_YEAR  (60 * 60 * 24 * 365)UL

Write a standard macro MIN that takes two parameters and returns the smaller one:

#define  MIN(A,B) ((A) <= (B) ? (A):(B))

What is the purpose of the preprocessor identifier #error:

#error : Stop compilation and display error message

Infinite loops are often used in embedded systems; how would you write an infinite loop in C:

C Language Issues in Embedded Development

Define the following using the variable a:

  • Integer: int a;

  • Pointer to an integer: int * a;

  • Pointer to a pointer that points to an integer: int ** a;

  • Array of 10 integers: int a[10];

  • Array of 10 pointers, where each pointer points to an integer: int * a[10];

  • Pointer to an array of 10 integers: int (* a)[10];

  • Pointer to a function that takes an integer parameter and returns an integer: int (* a)(int);

Please write down two functions of static:

C Language Issues in Embedded Development

The function of the const keyword:

C Language Issues in Embedded Development

Additionally, using const to define a variable:

C Language Issues in Embedded Development

The function of volatile:

A variable defined as volatile may be changed unexpectedly, and the optimizer must re-read the value of this variable instead of using a backup stored in a register.

Example of a volatile variable:

C Language Issues in Embedded Development

Embedded systems often require users to perform bit operations on variables or registers:

C Language Issues in Embedded Development

Embedded systems often require programmers to access specific memory locations, for example, setting the value of an integer variable at absolute address 0x67a9 to 0xaa66:

C Language Issues in Embedded Development

The concept of interrupts:

When an event occurs, the CPU stops executing the current program and switches to execute the program that handles the event. After handling the event, it returns to continue executing the original program.

ISR: Interrupt Service Routines.

C Language Issues in Embedded Development

What is the output of the following code?

C Language Issues in Embedded Development

When there are signed and unsigned types in an expression, all operands are automatically converted to unsigned types, so -20 becomes a very large positive integer, and the result of the expression is greater than 6, thus the output is > 6.

Dynamic memory allocation:

C Language Issues in Embedded Development

The typedef statement is used to define a new name for basic data types and exported data types:

C Language Issues in Embedded Development

Leave a Comment