Learn Pro­gram­ming With Code:: Blocks

On Win­dows

OpenSource For You - - FRONT PAGE -

This is an in­tro­duc­tion to a free and open source IDE –- Code::Blocks, which is ba­si­cally a C/ C++ IDE that sup­ports a cou­ple of com­pil­ers.

The In­te­grated De­vel­op­ment En­vi­ron­ment (IDE) is an ap­pli­ca­tion that can con­vert the mun­dane task of writ­ing hun­dreds of lines of code into a colour­ful process. It is a pro­duc­tiv­ity tool that in­creases the ef­fi­ciency of the pro­gram­mer. IDEs are gen­er­ally a com­bi­na­tion of a com­piler, a code edi­tor and a de­bug­ger. One of the most im­por­tant fea­tures of IDEs is that they are ‘in­tel­li­gent' enough to iden­tify and auto com­plete key­words and syn­taxes, thereby re­duc­ing the er­rors due to ty­pos. One of the first IDEs was made for Dart­mouth BA­SIC. It was a com­mand line-based IDE and had lit­tle re­sem­blance to its mod­ern day avatar. In 19T5, Mae­stro 1, a prod­uct from Soft­lab Mu­nich, be­came the world's first In­te­grated De­vel­op­ment En­vi­ron­ment for soft­ware. It was a big hit till the 1980s.

To­day, we have no short­age of IDEs. Choos­ing the right IDE for your work can be con­fus­ing when the op­tions be­fore you are many. CodeWWBlocks is avail­able on Linux, Win­dows and Mac plat­forms. But I will be deal­ing with CodeWWBlocks for the Win­dows plat­form. Things are pretty much the same on Linux too, ex­cept for the in­stal­la­tion part (as I have never used a Mac, I can­not comment on that plat­form).

The first sta­ble re­lease of CodeWWBlocks was in Fe­bru­ary 2008 and it had a ver­sion scheme 8.02 ( year.month of re­lease). The lat­est sta­ble ver­sion of CodeWWBlocks is 12.11. It sup­ports mul­ti­ple com­pil­ers, in­clud­ing MinGW/GCC, Dig­i­tal Mars, Mi­crosoft Vis­ual C++, Bor­land C++, Wat­com, LCC and the In­tel C++ com­piler.

In­stalling Code::Blocks

When you visit the down­loads page of CodeWWBlocks, http://www.Code::Blocks .org/down­loads/26#win­dows, you will find four op­tions. Iden­ti­fy­ing the cor­rect pack­age is your first task. I will ex­plain the bi­na­ries that are avail­able for Win­dows, but the same op­tions are avail­able for Linux and Mac plat­forms too. 1. Code::Blocks -12.11-setup.exe— This pack­age con­tains just CodeWWBlocks and does not have the com­pil­ers. This is suit­able for those who al­ready have any one of the sup­ported com­pil­ers on their sys­tem. It is just a 28.2 MB pack­age. 2. Code::Blocks -12.11-se­tup_user.exe— This pack­age is the same as the ear­lier one but is for peo­ple us­ing sys­tems to which they have no ad­min rights. 3. Code::Blocks -12.11mingw-setup.exe— This pack­age is a com­plete set with CodeWWBlocks and the GCC com­piler. It is like a fresh in­stall. Be­gin­ners will find this con­ve­nient, al­though it is a 96.8 MB pack­age to down­load. 4. Code::Blocks -12.11mingw-se­tup_user.exe— Again, this is the same as the one above but is for users who have no ad­min rights on their sys­tem. Once you have iden­ti­fied the pack­age you re­quire, down­load­ing it and in­stalling it is quite easy. Just fol­low the in­struc­tions on the in­stal­la­tion wizard. For mack­ages 1 and 2, which do not in­clude the com­piler, once in­stalled, CodeWWBlocks au­to­mat­i­cally looks for the com­piler.

The first pro­ject

Once you have your sys­tem live and kick­ing, it’s time for some se­ri­ous ac­tion. Let’s start CodeWWBlocks.

You will get a screen shot that looks like the one in Fig­ure 1. To start a new pro­ject you can click on the op­tion ‘ Cre­ate New mro­ject' on the wel­come screen or from File-> New-> Projects. Now a new dia­logue box should ap­pear ( see Fig­ure 2).

You will find a big list of the type of projects you can do in CodeWWBlocks. For this tu­to­rial, we will go ahead with the con­sole ap­pli­ca­tion. Once the op­tion is se­lected, click OK and that will take you to a wizard where ev­ery­thing is pretty straight­for­ward. First, you will be asked whether you want to code in C or C++, then you will be asked for de­tails like file­name, path, etc. Once this is done, you can see the pro­ject struc­ture in the ‘ Man­age­ment’ win­dow (the ex­treme left win­dow of CodeWWBlocks). Since I have se­lected C as the pro­gram­ming lan­guage, there is a file in my pro­ject struc­ture called ‘ main.c’ where all my code will go.

Now you have your main.c file, which you can mod­ify. For now, it has the nor­mal ‘ hello world’ pro­gram. #in­clude<stdio.h> int main() { printf("Hello World!");

re­turn 0;

}

Hit F9, which will first com­pile the pro­gram and if there are no er­rors, the pro­gram will be ex­e­cuted. You can mod­ify this main.c file and press F9 to com­pile and run.

Note: The pro­gram bi­na­ries that you cre­ated are avail­able in the pro­ject folder.

De­bug­ging

Af­ter com­pi­la­tion, if there are any er­rors, CodeWWBlocks, like all other IDEs, pro­vides a vis­ual in­di­ca­tion on the places where the er­ror has oc­curred ( mlease re­mem­ber that only syn­tac­ti­cal er­rors are dis­played). The CodeWWBlocks de­bug­ger has full break­point sup­port. It also al­lows the users to de­bug their pro­gram by us­ing the lo­cal func­tion sym­bol and ar­gu­ment dis­play, user- de­fined watches, call stack, dis­as­sem­bly, cus­tom mem­ory dump, thread switch­ing, CmU reg­is­ters, and GNU GDB in­ter­face. For de­bug­ging with GDB, go to Menu -> Pro­ject -> Build Op­tions and make sure that the pro­ject is com­piled with the -g ( de­bug­ging sym­bols) com­piler op­tion on, and the -s ( strip sym­bols) op­tion off. This en­sures that the ex­e­cutable has de­bug sym­bols in­cluded. Then you can set tog­gle.

Some ex­tra fea­tures

Track­ing mod­i­fi­ca­tions

CodeWWBlocks pro­vides a fea­ture to track mod­i­fi­ca­tions within a source and to show a bar in the mar­gin for the changes. Mod­i­fi­ca­tions are marked with a yel­low change bar, and mod­i­fi­ca­tions that are al­ready saved will use a green change bar. You can nav­i­gate be­tween your changes via the menu ‘ Search -> Goto next changed line’ or ‘Search -> Goto pre­vi­ous changed line’. The same func­tion­al­ity is also ac­ces­si­ble via the short cuts, Ctrl-F3 and Ctrl-Shift-F3.

De­fault code

One very nice fea­ture that I like in Code::Blocks is the ‘De­fault Code’. I am al­ways ir­ri­tated by the fact that when­ever I have to code, I have to type all those #InFOuGHs, int main(), etc. For­tu­nately, this par­tic­u­lar fea­ture in Code::Blocks al­lows you to set a de­fault code that will be present in ev­ery new file you cre­ate. 7his fea­ture is use­ful not just to hob­by­ists like me but also to pro­fes­sional coders. 6ome­times a com­pany's cod­ing pol­icy may reTuire sources to have a stan­dard de­sign with author name, date, etc. This pre­de­fined con­tent is called de­fault code. This set­ting can be se­lected un­der ‘ Set­tings -> Edi­tor - De­fault Code’.

The de­fault ‘ Hello world’ pro­gram in our first ex­am­ple is ac­tu­ally the de­fault code; you can mod­ify it and add any­thing you want there.

Bored with cod­ing?

No mat­ter how pas­sion­ate you are about cod­ing, af­ter a point, when you are stuck with your code and feel noth­ing works, it’s Tuite nat­u­ral to get ir­ri­tated. That’s when Code::Blocks can even help you re­lax by pro­vid­ing some en­ter­tain­ment. The clas­sic games of Snake and Tetris are avail­able from the ‘ Plug­ins ->BYO Games’ menu. In or­der to en­sure that you only spend a limited time on recre­ation, there is an op­tion to set the amount of time for which you are al­lowed to play, which is avail­able in the ‘ En­vi­ron­ment-> Set­tings’ menu.

I have briefly touched on some of the fea­tures of Code:: Blocks that might be use­ful to pro­gram­mers, but this is not where it ends. Code:: Blocks has many more plug- ins and fea­tures, like ‘ Auto ver­sion­ing’, where it gen­er­ates the ver­sion num­ber, and a ‘ todolist plugin’. It also sup­ports a wide va­ri­ety of com­pil­ers and can im­prove the ef­fi­ciency of your cod­ing skills. Hope this ar­ti­cle will be help­ful to at least some coders out there, who are not fa­mil­iar with Code:: Blocks.

Fig­ure 2: New pro­ject Dia­logue Box

Fig­ure 3: Se­lect­ing the lan­guage

Fig­ure 1: The Code::Blocks wel­come win­dow

Fig­ure 5. A game of Tetris in Code::Blocks

Fig­ure 4: Se­lect­ing the com­piler

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.