Volatile unsigned int * const

In the next line of code, what is the purpose of the keywords const?

volatile unsigned int * const UART0DR = (unsigned int *)0x10009000;

I understand a bit volatile unsigned int *, but why there const?

+5
source share
3 answers

constand volatileare called "type classifiers." Their syntax is one of the most confusing things in C.

First of all, we are dealing with an ordinary variable. Typically, you specify the type specifier to the variable name: const int x;but as well to record it after the name of the variable: int const x;. The meaning is the same, the last syntax is simply confused.

: , . : int* x , int, - int.

- const int, const int* x. pointer-to-const-int, - const int. , int const* x, .

, , . - . , , . int*const x; const *. int, const int. ( const *, , , )

, , : const int*const x; , int.

const int x;          // x is a constant data variable
int const x;          // x is a constant data variable

const int* x;         // x is a non-constant pointer to constant data
int const* x;         // x is a non-constant pointer to constant data 

int*const x;          // x is a constant pointer to non-constant data

const int*const x;    // x is a constant pointer to constant data

const. volatile , ! ..

, , . , volatile const int* , volatile const. , , volatile int const * int volatile const * .., .

+12

volatile unsigned int *, const?

, , , ( ) .

:

volatile unsigned int * const UART0DR = 

.


volatile unsigned int const * UART0DR = 

.


volatile unsigned int const * const UART0DR = 

, .

+6

From http://cdecl.org

volatile unsigned int *const a
=>
declare a as const pointer to volatile unsigned int
+1
source

All Articles