C Language Issues in Embedded Development

Declare a constant using the preprocessor directive #define to indicate 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 directive #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, each pointing 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);

What are two functions of static:

C Language Issues in Embedded Development

Purpose of the const keyword:

C Language Issues in Embedded Development

Additionally, using const to define a variable:

C Language Issues in Embedded Development

Function of volatile:

A variable defined as volatile may be changed unexpectedly; the optimizer must re-read the value of this variable when it is used, rather than using a cached value in a register.

Example of a volatile variable:

C Language Issues in Embedded Development

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

C Language Issues in Embedded Development

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

C Language Issues in Embedded Development

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 an expression contains both signed and unsigned types, 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