15 October 2009

Microsoft C++ != ANSI C++

I am a little bit bitter with Microsoft. I am sure a lot of you out there feel the same way. Our reasons may be different though. My biggest problem with MS is that they take things, any things, and try to make them into their own brand that doesn't like to play well with others. Aside from this, I think that Windows is a great OS. Heck I can't not like it right? Everyone uses it. Well today they might, but in times past Windows was not even an option. Lets take a look back for a moment.

C was developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. Pretty cool huh. In 1983 the X3J11 committee, formed by the American National Standards Institute (ANSI), started the process of standardizing C.

I know what you are thinking...
"Well Seth, why are you telling me all this bunch of bull crap about the history of C and how you hate MS?"

If you are starting to put the pieces together you already know where this is going. If not just read on and try to imagine what things would be like if there were no standards. I want you to learn about a very bad, nay cursed evil.

Anyhow, while ANSI was creating standards for C, the same sort of thing was happening with C++. You can read all about the history of C++ here. It is nothing less than fascinating. The guys who came up with this, the purest form of C++, are the architects of the modern programming language C++. I kneel before you great oh great lords of code.

Now about this time, Microsoft walks up into the realm of software compilers. So far so good, there is nothing wrong with a little healthy competition when it comes to software.... Or is it...

World: Whats that MS is pulling out of his back pocket? MFC? StdAFX... Windows API? What is this trickery that you are pulling before the our eyes? And what the hell is .NET?
MS: Oh this? This is what the creators and ANSI want C/C++ to REALLY be. Besides we are making it EASIER for you to program.
World: Oh ok... But I thought that ANSI came up with a standard that C and C++ compilers are supposed to use.
MS: Bah hah foolish children, there is no other C++ but Microsoft C++. Look, you can make a dialog box with one single command now!
World: Oh ok... So I can use this to create software.
MS: Yes of course... Windows software. There really is no other OS out there so whatever. Here is a sort of class thing that accesses the windows registry with C++! How cool is that?
World: Oh ok... Cool I guess.
MS: Trust us, you won't even have to learn ANSI C/C++ to use our modified versions. Here's a C++ function to show your icon! Presto!
World: Oh ok... That does sound alot easier.

What I just did there was I told a little story. A story about how the world was tricked by Microsoft. I was tricked, but here's the thing. I didn't even realize I was tricked.

My first compiler was Visual C++ 6.0. Oh yes I shelled out some big bucks for that monster. As a cool bonus I got a membership with Microsoft's Developer Network and recieved free CD's about 4 times a year. I thought I had everything I would ever need in order to learn how to program.

Had I only had a mentor to steer me in the right direction.

As it turns out, I was headed down a road that I wish I never took because I feel like I wasted a couple of years learning the MS bastardized version of C++.

It wasn't until I started to dabble around with Linux that I realized there was something strange. At first it was a small trickle of questions. Whats this POSIX stuff? Curses? WTF? Then the flood gates opened and I knew I had been duped by MS. Those bastards.

Some of you may understand what I am talking about. Others maybe not so much. But I am here to tell you one thing.

Microsoft C/C++ is NOT ANSI C/C++

Do not make this mistake. Do not create an entire set of your own libraries that are based on Microsoft standards. While this is fine if you know for a fact that you will never ever leave the safe and comfy confines of Windows, be aware that once you cross that line into the world of X you are going to either have to gut your libs or write ports of MS functions just to make it compile.

So please if you don't learn anything from my blog, please just take this away. The reason for me telling you this will become more and more clear as I continue to guide you on this journey. For now just tuck it away in your mind... One more time because this is important:

(Microsoft C/C++) != (ANSI C/C++)

What's next? I will be talking about a few terms used within C++ & a few of the more simple things that most documentation won't tell you (but should, but leave it out because they assume you already know these simple things).

MinGW & Code::Blocks


I'm going to talk about MinGW and Code::Blocks. I know what you're thinking... "What did he just call me?" Well relax, I didn't call you any names. Eh yeah... I'll just dive right into it then...

MinGW


What is it?

MinGW is a contraction of "Minimalist GNU for Windows", is a port of the GNU Compiler Collection (GCC), and GNU Binutils, for use in the development of native Microsoft Windows applications. (from the mingw.org website)

What does it do?

This suite of tools will allow you to compile executables for Windows from the following languages:
  • C++
  • C
  • Fortran
  • Java
  • Ada
  • Assembly Language
Why should I get it?

It's free. It's also widely used and robust.

Ok, now that you know what MinGW is, you can forget about it. Unless you are an overachiever, in which case you can learn more here.

All you really need to know about MinGW is that MinGW is a free C/C++ compiler that comes bundled with Code::Blocks. You CAN use other compilers/debuggers with Code::Blocks, if you are some kind of wierd engineer working on DNA sequencing software on some database that resides on some ancient mainframe hardware that requires a certain build of a certain kind of compiler that only compiles a modified fortran dialect (chuckle, what a loser)...

Code::Blocks

What is it?

Code::Blocks is a free C++ IDE built to meet the most demanding needs of its users. It is designed to be very extensible and fully configurable. (from the codeblocks.org website) In short it is a highly advanced super-version of Notepad.exe.

What does it do?

This thing will let you type in the C/C++ script and then click a button and compile and execute it. Very cool. More information can be found here.

Why should I get it?

Ok this is kind of like asking the question would I rather walk to the store which is 5 miles away, or do I get in my car and ride on my butt to the store which is 5 miles away, letting the car do all the hard work. Yes in this case the software is the car. So unless you want to pretend you are a computer scientist from the late 1970's and like dealing with command line prompts, I highly recommend you get this software.

There you have it. Open Source software which will allow you to create your own software. How great is that? In this post I am only going to talk about what MinGW and Code::Blocks are and I have provided you with the links to the websites. I'll go over creating some simple programs next. So go ahead and download and install, and get ready for the ride of your LIFE! WOooooOOoO!

Code::Blocks / MinGW Bundle Download from Sourceforge

14 October 2009

Thumbs.DB Annihilator


Here is a computer program that I created that I call Thumbs DB Annihilator!

This program will search your hard drives for all those Thumbs.db files that Windows thinks it has to create and it will DELETE every single one of them. WARNING: This WILL DELETE all THUMBS.DB files on ALL YOUR DRIVES. (Turn off the Windows System feature that creates thumbs.db files)

This program is specifically written for Windows systems and I don't think it will compile on anything else. In this instance it does not matter because all I care about is deleting the thumbs.db files that Windows creates. I will get into creating code that will compile on more than one OS a little later.

Here is the link to the zip file from my Google site:

Thumbsdb.zip

This file has the executable in it and also has the Visual C++ workspace to build it if you have that. The following files should be in the zip file:

c_thumbsdb.cpp contains class CThumbsdbCleaner
c_thumbsdb.h contains definition for class CThumbsdbCleaner
thumbsdb.cpp contains int main(int argc, char* argv[])

If you are using MinGW (GNU C) to compile from command line type these lines into the command prompt to compile it:

g++ -c thumbsdb.cpp
g++ -c c_thumbsdb.cpp
g++ *.o -o thumbsdb.exe

You'll probably notice that it is kind of overly complex code for what it is, but there is a reason for it and I will build on it in the future. I also left in alot of commented out code that you can toy around with to make it delete other files. Be extremely careful with this or you may delete some things you don't want it to. For now, take some time and just look around into the C++ class and structure.

Even with the extra class file and header file, it is a very simple program. It just reads the disks folders and looks through them for the thumbs.db files and if it finds one it zaps it. It adds the total number of files it deletes and the size of the files in case you are curious.

The best way to use this program is from a command prompt, but you can just double click on it from windows and it will still work. The only downfall to executing it by double click is that you won't be able to see the final results because it will close the console window immediately after the program exits.

I will be posting more of my little projects as time passes.

I will talk about Code::Blocks and MinGW coming up...

Seth... Coder


Well it's been a while since I last posted anything on here, I could not really think of anything to post. Go figure.
What I have been doing is thinking about what I want this blog to become. I want to give my knowledge back to the world and to help aspiring coders. I want to share some of the pitfalls that I fell into while learning so that others do not waste thier time.
I am going to start posting some stuff about C++, PhP, and other programming languages and/or scripting tools. I've been dabbling with this sort of thing ever since my loving mother bought me a Commodore 64 when I was only 12 years old. Back then, Microsoft BASIC 2.0 was the operating system. I tore the machine apart and learned assembly language using the Commodore's 6510 (6502 based CPU). For whatever reason, I became obsessed with learning how it worked and how to make it do whatever I wanted it to do. Over the years I have upgraded my machines. C128, Amiga, 386, 486, Pentium, AMD, now um... Linux, FreeBSD, etc. All the while I have studied in great detail how to program the machines in various languages. I was using BBSs with 300 baud modems to connect to the FIDOnet in 1986.
By far, my favorite language is C/C++ so that is where I am going to primarily steer on this adventure. If I get off course with some wierd language like Ruby please someone talk some sense into me. If you know me please hit me in the face. (Yes that was a dig at Ruby)
So anyhow, I'll get started here.