System programming on C - c

I want to try to develop system software, drivers for devices. I know that C is low level programming language and it is very popular in this scope.
What compiler is better to use (only C, not C++)? and what libraries are used for system related stuff?
OS Windows.

If you wan to do Windows driver development, then you should look at the WDK - Windows Driver Kit. It should have most of what you need including tools, headers and libraries (and documentation).

For Windows look at the WDK and related MSDN documentation. The WDK includes Microsoft's compiler. http://www.microsoft.com/whdc/devtools/WDK/default.mspx
There is a lot to absorb there. If you're new to programming you should get some experience with C at the user application level and then try out Kernel development once you are comfortable with the language.

Related

How does one add <graphics.h> into GCC on a Windows computer for C? [duplicate]

I have been searching to get the source code of the header file <graphics.h> and its associated library in order to integrate it with my C++ program.
At the same time, I am interested in those cross-platform libraries that works on more than one compiler. Just to be more explicit, I am talking about those libraries that are used for drawing shapes, lines, and curves in C++.
<graphics.h> is very old library. It's better to use something that is new
Here are some 2D libraries (platform independent) for C/C++
SDL
GTK+
Qt
Also there is a free very powerful 3D open source graphics library for C++
OGRE
<graphics.h> is not a standard header. Most commonly it refers to the header for Borland's BGI API for DOS and is antiquated at best.
However it is nicely simple; there is a Win32 implementation of the BGI interface called WinBGIm. It is implemented using Win32 GDI calls - the lowest level Windows graphics interface. As it is provided as source code, it is perhaps a simple way of understanding how GDI works.
WinBGIm however is by no means cross-platform. If all you want are simple graphics primitives, most of the higher level GUI libraries such as wxWidgets and Qt support that too. There are simpler libraries suggested in the possible duplicate answers mentioned in the comments.
There is a modern port for this Turbo C graphics interface, it's called WinBGIM, which emulates BGI graphics under MinGW/GCC.
I haven't it tried but it looks promising. For example initgraph creates a window, and
from this point you can draw into that window using the good old functions, at the end closegraph deletes the window. It also has some more advanced extensions (eg. mouse handling and double buffering).
When I first moved from DOS programming to Windows I didn't have internet, and I begged for something simple like this. But at the end I had to learn how to create windows and how to handle events and use device contexts from the offline help of the Windows SDK.
The Borland Graphics Interface, the library fronted by the graphics.h header, has been re-implemented atop SDL. This brings support for modern hardware and operating systems (multiple operating systems, in fact, since SDL is fairly portable).
It can be downloaded here prebuilt for a variety of common desktop targets.
Or if you wish to (or must) build it from source, here is a github mirror.
Note that it is a port of a very old software library and will run atop modern tools, so you should check with the instructor if you intend to use it for class assignments. It would be irritating to fail an assignment because you used idioms that require support from a modern compiler and find that they do not compile on a marking system from the 1980s.
You may find it better to get and develop with a virtual machine clone of the marking system to prevent nasty surprises.
graphics.h appears to something once bundled with Borland and/or Turbo C++, in the 90's.
http://www.daniweb.com/software-development/cpp/threads/17709/88149#post88149
It's unlikely that you will find any support for that file with modern compiler. For other graphics libraries check the list of "related" questions (questions related to this one). E.g., "A Simple, 2d cross-platform graphics library for c or c++?".

Dos.h + Pc.h in C and Windows Vista

I am currently looking to work with Mesa3D to create a software rendered graphic application with OpenGL.
I am looking a a few tutorials right now on how to use it, and many are written with DOS or older versions of Windows in mind. As I run Vista I don't seem to have the right files I need.
The Mesa3D tutorial I am using uses outportb() and a few other commands which I can't seem to get working. After looking around I have found you require the 2 include files:
dos.h
pc.h
These do not seem to be found within the Window's SDK that comes with Visual Studio 2010 (Express) or even the older version of 2005 (Professional) which I currently have.
They seem to be found with the DJGPP compiler that only works under DOS and is not supported in Vista, even with compatability mode. Running DosBox still does not get this to work.
I am wondering - is there perhaps a new functions replacing outportb or can I use these DJGPP files with my C/C++ complier with VS or PellesC (which I find better for C-only programs)?
In addition the conio.h include file I have with both VS and PellesC doesn't have the textmode() function, but the DJGPP version does.
If anyone could help either getting DJGPP working on Vista or allowing me to use the dos,pc and conio.h files from DJGPP with either VS or PellesC that'd be a great help!
Port-manipulating functions will simply not work in Win32 programs. Either use Win32 APIs to do I/O (rendering included) or stick to DOS and run your program in DOS or whatever DOS emulator you can find that works. Vista and later Windows won't run most DOS programs directly as the support for DOS is either severely reduced or removed altogether (e.g. in 64-bit Windows).
The low-level hardware access that functions like outportb give you is not available to programs in modern Windows environments. Such capabilities are reserved for specially-trusted code (OS internals and drivers). You need to go through higher-level APIs or drivers in order to access the same functionality.
The Mesa3D website has a readme for Windows developers that has information about what you need to install and configure. It also references some official demo code that you can use as the basis for your project. The Mesa3D website also has a repository full of demo programs that will probably serve as better examples than the out-of-date tutorials that you mentioned.
Do not use 16bit compilers on vista and higher.. instead use DOSBOX to run your programs.

Tools like PVS-Studio for static code analysis in C projects?

I'm looking for some alternatives to the PVS-Studio tool, in order to run some static code analysis in C projects. Do you guys have any suggestions?
You don't state what you need, nor platform (your nick suggests linux),
but I use(d) these in past with great impact on my code:
Cppcheck (great eclipse plugin integration, its cpp but It does actually support C99 - plugin is called cppcheclipse)
Sparse (can be inegrated into eclipse by using "external tools")
Splint (eclipse CDT has plugin)
Codan (internal part of eclipse)
Intel SSA (I believe this can be accessed from Intel Compaser or Parallel studio, both of which provide free non-commercial like license and official Intel eclipse integration plugin)
All of these can be integrated at the same time into eclipse (using plugins, "run external tools" ar internally) and provide real time checking and analysis within Eclipse CDT IDE for linux programmers.
If you want more, there is alsa awesome set of tools in Frama-C.
These are best free tools (not necessarily opensource or free for commercial use) for static analysis I know of and they really make nice synergy with eclipse.
Sorry for advertising eclipse btw, except for Codan tools, these are accessible by other means (cppcheck provides simple GUI I believe, and others are all accessible from shell).
You don't mention what features you're looking for, but you can check out Vigilant Sentry and see if it meets your needs. It does static analysis of C and C++ programs, and has a plugin system for developing your own custom checks.

C + GUI + Mac OS

i know c and I want to develop applications with GUI for Mac OS. Where do I start?
Learn Objective-C.
Then pick up Cocoa (and all of the Frameworks that go with it)
Buy Apple computer
Install XCode from supplied DVD
Run Software Update from system menu
Run XCode
Select Help menu, select "Developer Documentation"
Click on any of the many things that say things like "Quick Start" or "Getting Started with XCode".
Read
Program
GoTo 7.
Downloading xcode would be your first step. It's the main development environment for mac development and it's free. Then you'd want to get a book on Cocoa w/ Objective-C or Carbon w/ C. Apple is pushing Cocoa more.
The Simple DirectMedia Layer (SDL) library is yet another option. It is a cross-platform development library that can be used to write GUI-based applications for Mac OS in C.
While there is Carbon, it's a framework that's not first-class going forward. If you want to make sure that you can access all of the features of Mac OS X, you'll want to learn Objective-C and use Cocoa.
I believe all Macs nowadays come with a complete set of development tools. They're not pre-loaded on the Mac, but are in the CD-ROM or DVD-ROM package. Alternately, you can go to Apple's site and poke around until you find the development section, and download Xcode. (It'll be the same thing, but possibly a newer version.)
Mac OSX uses a language called Objective-C, which is C extended with OO abilities that are more like Smalltalk than the more usual Simula type (in C++, say). While you don't actually have to use it much, it is how you'll be writing interface code.
Further, it uses the Cocoa framework. There was a framework called Carbon, which was a cleanup and redesign of the pre-Mac OSX Macintosh system facilities, but it's being left behind.
You can find free information on either if you look, or you can buy books on them. Books are probably a better resource to learn from.
You can also try with QT and C++. Try here:
http://qt.nokia.com/products/platform/qt-for-mac

Strict C Win GUI programming

Good day folks, I'm in a need of a bit of guidance.
Basically, I'm a webdev who knows some C from the past, but I've only developed somewhat simple console apps for *nix.
Shortly, I want to develop a simple Win program with a GUI and not get my hands into any of the following technologies:
.NET C#
Java
C++ (especially this one)
Because I have nor the time nor the need for it currently.
1). Can I use wxWidgets without resorting to cpp (if not, what other native looking and lightweight widget toolkit would you suggest?)
2). Can I use OpenCV with strict C? (no templates, inline functions, etc)
3). Should I look for other options for a compiler besides MinGW? Is Intel one worth investigating? (AFAIK, it has a restrictive license).
4). What IDE of the following would you suggest for windows / c programming
Dev-C++
Eclipse with appropriate plugins (can't remember the exact one)
Any text editor + *.bat for compiling??
Thanks!
If you're interested in learning C-based Windows programming directly, and not using other intermediate tools:
There's a really good reference book by Charles Petzold called Programming Windows. It's definitely the way to get started. Absolutely everything is crystal clear, and you never need C++.
The Windows API, as a whole, is built for C programmers. All the fancy stuff like an actual application window is passed back as "HANDLE"s, which are more-or-less just pointers into the OS's object table. You as a programmer never have to deal with objects, just their HANDLEs.
Also, this particular book does a good job describing the Windows event-loop. If you're unfamiliar with it, it is described in generous detail.
Good luck!
For C Windows GUI programming the easiest thing is VC++ (any version since 6.0) and The Charles Petzold Programming Windows book.
The free Express version of the Microsoft compiler should work fine - I'm not sure if you'd have to download the Platform SDK or if it comes with one.
You can write Windows GUI programs in straight C. Download the Windows SDK and look at the "GENERIC" sample (I assume it's still in there). This is pretty much the minimal code required for a Win32 app, and it's in plain-ol' C.
Edit: Hmmm, it doesn't appear to be installed on this laptop. You can find it online here.
It might be worth reconsidering C#.NET. You could easily learn C# in a couple days, and be developing slick apps very quickly. Straight C-based windows libraries, particularly Win32, are BRUTAL in comparison. You'd spend a week just to write a simple app that would take minutes in C#.
The only C-based toolkit I can think of is the Windows port of GTK+. I have no experience using it in the Windows environment though. It is very mature on the Linux side though, and may be good enough if your needs are simple.
Learning the Win32 API is hard! But like others have stated, Petzold's book is the way to go if you insist on going down that path.
My opinion is that developing a Windows GUI using only C and the Win32 API would be harder to learn than picking up just enough C++ to utilize one of the C++-based frameworks. You could still do the majority of your work in plain C.
As for free IDEs, I would go with Visual Studio 2008 Express Edition.
You don't need anything.
Just use C and Win32 api , like real programmers, not kids..
See the VS Win32 wizard
Regarding wxWidgets, you can use https://sourceforge.net/projects/wxc
I never actually heavily used it, so I'm not aware of its maturity.
Mingw and Microsoft Visual C++ are my favorite compilers. Remember you can always use strict C and compile it using a C++ compiler, since valid C is almost always valid C++.
For windows, I've used Dev-C++ in the past, but nowadays Microsoft Visual C++ seems a better solution.
If you're going for text editor+bat, check out Notepad++.
EDIT: Just to clarify, using Microsoft Visual C++ does NOT mean learning C++. You can use C in it perfectly because - I repeat - valid C is often valid C++. Don't want C++? No problem. Just stay away from the C++-only features and you're still safe in a C++ compiler.
EDIT: Roger Lipscombe has noted in the comments that a pure C compiler is available in Microsoft's Visual C, using the /TC switch.

Resources