I would like to know: is there a direct access to the equipment in с++ or in с++ ? That is, can I only process data from the mouse with, for example? Can I work with video memory?

  • 2
    You can of course, if the operating system allows. And now the OS itself is usually in C and they write - Mike
  • @Mike, can I have some links? Can there be literature on this topic? - Alexander Vogrik
  • In general, yes, but all these charms on KernelMode. The standard language for drivers is C, but they also write in C ++. - Alexey Sarovsky
  • @AleksandrVogrik You first decide on the operating system. then you will need to learn its API already. And to decide why you need it, you may have to write a driver or something else in the kernel space. You can see the linux source, there almost all work with the equipment on C is there. - Mike
  • one
    @AleksandrVogrik what does "your" mean? If you are in Windows, then Windows draws everything, and you will basically use its functions (such as CreateWindow ()) - Alexey Sarovsky

2 answers 2

In itself, C / C ++ does not have such opportunities - high-level languages ​​imply some level of abstraction from equipment (different languages ​​have different levels, for example, Pascal has abstraction levels higher).
These features are provided by the operating system, if any.
If there is no operating system or a lower level code (for example, a driver) is written, then the work with the equipment is usually built like this.

There is a controller of a certain device (for example, a keyboard). This controller has a set of registers with the help of which it is tuned to the desired mode of operation and through which interaction with the controller is performed. These registers are mapped to some known addresses in the processor’s memory and these addresses are used to access the registers (there is also a separate address space for these purposes: ports). For example:

 #define pREG_UART1_BAUD (volatile unsigned long *)0xFFFF000C *pREG_UART1_BAUD = 115200; 

Details depend on the controller and are described in its documentation.

If you want to dive to the lowest level, you can read about programming microcontrollers (in Russian there are books about PIC, AVR, ARM). There are no operating systems (at least in the usual sense) and all the work is done directly.

    In C ++ there is access to equipment only in the form of reading / writing volatile variables.
    Almost all compilers have tools (intrinsiki) for working with hardware ports, and other means of the target platform.

    However, all this is available only at the level of the operating system (the driver and the OS itself).
    For user applications in Windows, nothing like this is available.

    In other words, if you are writing an OS or a driver, then yes, you can work with video memory. From the normal application - no, because the OS prohibits it.

    • And what kind of kernel mode? Is this all also in the framework of the OS? - Alexander Vogrik
    • "kernel mode" is the access level of the OS kernel. - Abyx
    • understood, I will know - Alessander Vogrik
    • More specifically, not only from the kernel, the driver can voluntarily share resources to the application layer. - Cerbo