Is there anyway that c++ can access hardware without going through an OS? The OS must do it somehow.
Is there anyway that c++ can access hardware without going through an OS? The OS must do it somehow.
In simple terms, no. You must go through the OS.
This question is highly specific to whatever platform and OS you're developing for. On x86 processors (most PCs), it's the above no - specific access is done by the OS. You, as a plain old application, must go through the OS. How the OS does it may not be allowable in an app. (There are, for example, certain instructions for x86 processors that only the OS can execute.)
long time; /* know C? */
Unprecedented performance: Nothing ever ran this slow before.
Any sufficiently advanced bug is indistinguishable from a feature.
Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
The best way to accelerate an IBM is at 9.8 m/s/s.
recursion (re - cur' - zhun) n. 1. (see recursion)
If your OS is DOS, or any number of real time embedded operating systems - sure.
If your OS is a protected OS like Linux or any of the NT series from Microsoft, then no.
Be specific.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
To expand a bit on the previous replies:
the OS, if it's a modern 32-bit OS, will allow hardware access at kernel level. Anything running as regular C or C++ code will not be allowed to touch any hardware. This is because we don't really want applications to "mess" with hardware in an disorganized manner - if you have two applications that both wants to access the same hardware, the result would likely be quite unpredictable (and with even more certainty, not what either application expects).
The way that the OS actually gets to the hardware is via drivers. Drivers can be written in C++ in some OS's, but for the two most common PC OS's, Linux and Windows, you'd have to jump through hoops to make a driver in C++, and there are many limits on what you can and can't do in C++ when you have jumped through those hoops (exceptions, global objects for example). It can be done, but it's only really practical to do so if you have a large amount of existing code, or you are writing a very large driver that will definitely benefit from C++ coding. I'd hazzard a guess that less than 1% of existing Windows drivers in production are using C++.
This is not the case for all OS's tho: Windows CE for example uses a completely different driver architecture, that is designed entirely around drivers written in C++.
And of course, as Salem indicates, "simple" OS's have no protection between user-code and hardware, so any application can touch anything in the system - whether it's doing it in the right way or not.
Finally, writing drivers, whether that is with or without protection, tends to get pretty complicated pretty quickly - it is not a beginner task by any means.
As Salem says: Provide more specifics about what you are trying to do, and we can probably help you find a solution.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
The part about drivers is what I problaby really meant to ask. Any tips on where to start?
What OS?
Linux - get the kernel source and the code is in the "driver" section (from memory).
Windows - get the Windows DDK from the MS website. It's pretty large, but there is a fair bit of source and all the tools you need (including a compiler that it guaranteed to be compatible with the kernel).
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Whats a kernel?
It's "the actual OS", the "core" of the operating system, that handles the processes, memory and processor time (and any other resources that need to be managed).
You may want to read up on operating systems and such, for example Andrew Tannenbaum's book [1]:
http://www.pearsonhighered.com/educa...USS_01DBC.html
[1] This is probably the best book on the subject ever written, and it's the book that made a certain Linus Torvalds decide to write his own OS. documented here amongst other places
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Anywhere I can get an online book for free?
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
What does the book exactly explain? Have you read it?
Yes, I studied this book in a "Operating System Design" class many years ago. It covers everything from basic principles of how an OS works, all the way to concrete examples of how modern OS's do things in the "real world". You can not get a better book on that subject.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thanks for all the help but ill stick with working through an OS.