Okay, while I am not on the C/C++ committees, it has come to my attention over the more recent months and years that the core languages are simply not capable of handling modern devices - particularly dealing with PCs. If you search the archives of several of the many lists I subscribe to, you will frequently find programmers asking about how to use ANSI C/C++ to do:
1) Single keypress keyboard input.
2) Drawing graphics on the screen.
3) Printing to a printer.
4) Accessing USB devices (e.g. a scanner).
5) Responding to mouse movement.
Every single time, without fail, someone replies saying that these are not standard. I have, on occassion, jokingly made the suggestion that C was designed to output to a dot matrix or line printer. So, all of these discussions have me thinking about what to do. The result of all this thinking is that, because C is incapable of these things, people have to resort to using OS-level APIs. One of the major goals of C/C++ was to make it able to compile code for any platform. However, the ANSI standard is simply not cut out to handle devices that are portable to other platforms. Now, I realize embedded devices don't have the capability of a mouse, but think instead of the pen surface of a PDA as being a generic "coordinate input device". There are numerous scenarios where a "coordinate input device" would be useful even in an embedded environment. The keyboard is a "button device". A mouse button is a "button device". The screen (or a "window" in certain environments) is a "coordinate output device" (but can also be an input device). The printer is a "coordinate output device". For all intents and purposes, a "button device" could also be considered a "coordinate input device".
I think the major problem here is that the committee failed to realize that not only could they differentiate between a hosted environment and a non-hosted environment, they could also differentiate between a hosted environment with support for attached devices and a hosted environment without such support. So, how would someone go about defining a device extension standard that supports my idea of generic devices? Well, the first thing to do is add a set of functions to the standard that support the idea. My first rough stab at the prototypes would look something roughly like:
DEVLIST *devlistopen(const char *devicetype);
char *devlistread(DEVLIST *dlp, size_t device);
int devlistclose(DEVLIST *dlp);
DEV *devopen(DEVLIST *dlp, size_t device, void *openinfo);
int devread(DEV *dp, void *readinfo);
int devwrite(DEV *dp, void *writeinfo);
int devclose(DEV *dp);
That's pretty much it. Now you are thinking, "What in the world are those void pointers doing there?!" This is the beautiful part. At this point, ANSI hands off the responsibility of defining the openinfo, readinfo, and writeinfo data types and structures along with device types to another organization. So, say you come up with a new device for USB (let's say you invent the scanner) and want to get it standardized so C/C++ programmers can use it with ANSI-standard functions. The organization will assign your device with a generic device type and you pick a name for your brand of the device type using their online database. Then, you work with the organization to come up with a standard set of openinfo, readinfo, and writeinfo structures that are suitable for any PC scanner device to use. You will note that this method only allows for a single structure for each call. If you need another structure, you actually have two differing types of devices (e.g. mouse movement versus mouse buttons) and therefore require two separate interactions with the organization. The best part of this is that ANSI can leave themselves out of this end of things.
The only remaining issue is determining how to get your device into the compiler. Most compiler writers will likely develop some sort of plug-in style architecture for the device developers to utilize (e.g. DLLs for Windows-based compilers). As a programmer, all you will care about is making code and have it work the first time it compiles. Something like this might be used for determining the coordinate position of the mouse:
dlp = devlistopen("PC_MOUSEMOVE");
if (dlp != NULL)
dp = devopen(dlp, 0, &pmo);
if (dp != NULL)
printf("Current mouse coordinates: %li, %li\n", pmr.x, pmr.y);
ANSI C/C++ only recognizes four devices: Files, stdin, stdout, and stderr. The concept of monitors, printers, scanners, telephones, modems, audio devices, video cards, the Internet (e.g. sockets), and even memory (in some respects) are all non-standard. All I ask for is a handful of functions to be added to the standard for hosted implementations that support the concept of devices.
See what I'm trying to get at here? There are only ANSI-standard calls being made (assuming you can imagine it as part of the standard - humor me if you can't). If ANSI doesn't want concepts like mice and keyboards in the standard, that's fine, but they need to give the rest of us a way to extend the standard that is acceptable by the standard.