A
A
Alexander2020-06-10 15:31:11
C++ / C#
Alexander, 2020-06-10 15:31:11

What does const volatile mean?

There is a port address 0x30.
What does this expression mean? And why cast the address to such a pointer?
const volatile char *port = (const volatile char *) 0x30;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2020-06-10
@Shemapp

const - to exclude attempts to write to it.
volatile - every time you access, go to the address and take data, and not cache.
If some cell in memory (in this case at address 0x30) is changed by another thread or, for example, by hardware, it is volatile.
It would be better to write

const volatile char* const port = (const volatile char *) 0x30;

Even better (C++11 and non-portable)
constexpr const volatile char *port = (const volatile char *) 0x30;

Better yet, Pascal
var
  SomePort : byte absolute $30;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question