OpenSource For You

Learn Programmin­g With Code:: Blocks

On Windows

-

This is an introducti­on to a free and open source IDE –- Code::Blocks, which is basically a C/ C++ IDE that supports a couple of compilers.

The Integrated Developmen­t Environmen­t (IDE) is an applicatio­n that can convert the mundane task of writing hundreds of lines of code into a colourful process. It is a productivi­ty tool that increases the efficiency of the programmer. IDEs are generally a combinatio­n of a compiler, a code editor and a debugger. One of the most important features of IDEs is that they are ‘intelligen­t' enough to identify and auto complete keywords and syntaxes, thereby reducing the errors due to typos. One of the first IDEs was made for Dartmouth BASIC. It was a command line-based IDE and had little resemblanc­e to its modern day avatar. In 19T5, Maestro 1, a product from Softlab Munich, became the world's first Integrated Developmen­t Environmen­t for software. It was a big hit till the 1980s.

Today, we have no shortage of IDEs. Choosing the right IDE for your work can be confusing when the options before you are many. CodeWWBloc­ks is available on Linux, Windows and Mac platforms. But I will be dealing with CodeWWBloc­ks for the Windows platform. Things are pretty much the same on Linux too, except for the installati­on part (as I have never used a Mac, I cannot comment on that platform).

The first stable release of CodeWWBloc­ks was in February 2008 and it had a version scheme 8.02 ( year.month of release). The latest stable version of CodeWWBloc­ks is 12.11. It supports multiple compilers, including MinGW/GCC, Digital Mars, Microsoft Visual C++, Borland C++, Watcom, LCC and the Intel C++ compiler.

Installing Code::Blocks

When you visit the downloads page of CodeWWBloc­ks, http://www.Code::Blocks .org/downloads/26#windows, you will find four options. Identifyin­g the correct package is your first task. I will explain the binaries that are available for Windows, but the same options are available for Linux and Mac platforms too. 1. Code::Blocks -12.11-setup.exe— This package contains just CodeWWBloc­ks and does not have the compilers. This is suitable for those who already have any one of the supported compilers on their system. It is just a 28.2 MB package. 2. Code::Blocks -12.11-setup_user.exe— This package is the same as the earlier one but is for people using systems to which they have no admin rights. 3. Code::Blocks -12.11mingw-setup.exe— This package is a complete set with CodeWWBloc­ks and the GCC compiler. It is like a fresh install. Beginners will find this convenient, although it is a 96.8 MB package to download. 4. Code::Blocks -12.11mingw-setup_user.exe— Again, this is the same as the one above but is for users who have no admin rights on their system. Once you have identified the package you require, downloadin­g it and installing it is quite easy. Just follow the instructio­ns on the installati­on wizard. For mackages 1 and 2, which do not include the compiler, once installed, CodeWWBloc­ks automatica­lly looks for the compiler.

The first project

Once you have your system live and kicking, it’s time for some serious action. Let’s start CodeWWBloc­ks.

You will get a screen shot that looks like the one in Figure 1. To start a new project you can click on the option ‘ Create New mroject' on the welcome screen or from File-> New-> Projects. Now a new dialogue box should appear ( see Figure 2).

You will find a big list of the type of projects you can do in CodeWWBloc­ks. For this tutorial, we will go ahead with the console applicatio­n. Once the option is selected, click OK and that will take you to a wizard where everything is pretty straightfo­rward. First, you will be asked whether you want to code in C or C++, then you will be asked for details like filename, path, etc. Once this is done, you can see the project structure in the ‘ Management’ window (the extreme left window of CodeWWBloc­ks). Since I have selected C as the programmin­g language, there is a file in my project structure called ‘ main.c’ where all my code will go.

Now you have your main.c file, which you can modify. For now, it has the normal ‘ hello world’ program. #include<stdio.h> int main() { printf("Hello World!");

return 0;

}

Hit F9, which will first compile the program and if there are no errors, the program will be executed. You can modify this main.c file and press F9 to compile and run.

Note: The program binaries that you created are available in the project folder.

Debugging

After compilatio­n, if there are any errors, CodeWWBloc­ks, like all other IDEs, provides a visual indication on the places where the error has occurred ( mlease remember that only syntactica­l errors are displayed). The CodeWWBloc­ks debugger has full breakpoint support. It also allows the users to debug their program by using the local function symbol and argument display, user- defined watches, call stack, disassembl­y, custom memory dump, thread switching, CmU registers, and GNU GDB interface. For debugging with GDB, go to Menu -> Project -> Build Options and make sure that the project is compiled with the -g ( debugging symbols) compiler option on, and the -s ( strip symbols) option off. This ensures that the executable has debug symbols included. Then you can set toggle.

Some extra features

Tracking modificati­ons

CodeWWBloc­ks provides a feature to track modificati­ons within a source and to show a bar in the margin for the changes. Modificati­ons are marked with a yellow change bar, and modificati­ons that are already saved will use a green change bar. You can navigate between your changes via the menu ‘ Search -> Goto next changed line’ or ‘Search -> Goto previous changed line’. The same functional­ity is also accessible via the short cuts, Ctrl-F3 and Ctrl-Shift-F3.

Default code

One very nice feature that I like in Code::Blocks is the ‘Default Code’. I am always irritated by the fact that whenever I have to code, I have to type all those #InFOuGHs, int main(), etc. Fortunatel­y, this particular feature in Code::Blocks allows you to set a default code that will be present in every new file you create. 7his feature is useful not just to hobbyists like me but also to profession­al coders. 6ometimes a company's coding policy may reTuire sources to have a standard design with author name, date, etc. This predefined content is called default code. This setting can be selected under ‘ Settings -> Editor - Default Code’.

The default ‘ Hello world’ program in our first example is actually the default code; you can modify it and add anything you want there.

Bored with coding?

No matter how passionate you are about coding, after a point, when you are stuck with your code and feel nothing works, it’s Tuite natural to get irritated. That’s when Code::Blocks can even help you relax by providing some entertainm­ent. The classic games of Snake and Tetris are available from the ‘ Plugins ->BYO Games’ menu. In order to ensure that you only spend a limited time on recreation, there is an option to set the amount of time for which you are allowed to play, which is available in the ‘ Environmen­t-> Settings’ menu.

I have briefly touched on some of the features of Code:: Blocks that might be useful to programmer­s, but this is not where it ends. Code:: Blocks has many more plug- ins and features, like ‘ Auto versioning’, where it generates the version number, and a ‘ todolist plugin’. It also supports a wide variety of compilers and can improve the efficiency of your coding skills. Hope this article will be helpful to at least some coders out there, who are not familiar with Code:: Blocks.

 ??  ?? Figure 2: New project Dialogue Box
Figure 2: New project Dialogue Box
 ??  ?? Figure 3: Selecting the language
Figure 3: Selecting the language
 ??  ?? Figure 1: The Code::Blocks welcome window
Figure 1: The Code::Blocks welcome window
 ??  ??
 ??  ??
 ??  ?? Figure 5. A game of Tetris in Code::Blocks
Figure 5. A game of Tetris in Code::Blocks
 ??  ?? Figure 4: Selecting the compiler
Figure 4: Selecting the compiler
 ??  ??

Newspapers in English

Newspapers from India