Printing hex values using cout()

I wanted to display hex numbers and came across setf() & unsetf() functions which are quite useful to know of! There are different kinds of flags & masks you can use as well.

Please refer http://www.cplusplus.com/reference/iostream/ios_base/setf/ for more information.

#include <iostream>
using namespace std;

int main()
{
    int num = 255;
    cout.setf(ios::hex, ios::basefield);
    cout << "Hex: " << num << endl;

    cout.unsetf(ios::hex);
    cout << "Original format: " << num << endl;

    return 0;
}
0  

How does a compiler tie an error message back to the source code?

Usually we see (C++/.NET) programs throwing exception messages which are not very informative. But at-least they direct me to the line from where the problem originated. How does the compiler do that?

Compilers have two modes when building a program – DEBUG & RELEASE.

By default, compiler builds the program in the debug mode & adds line-number information that maps the lines in source code to the corresponding lines of machine code. For example, the map might say that line 200 of machine code in the executable code was created from the C++ source code on line 16.

This debug information consumes a lot of space & it makes the executable file larger & slower. To address this problem, the compiler also has a release mode in which the debug information is stripped out.

0  

Back after a while …

A lot has changed around me in the last one year or so 🙂 I’ll start posting new items on my blog on a regular basis going forward.

0  

Semantic Test Plan – KFrog Language

This post is an extract from one of my earlier project under Prof. Alfred Aho for the course – Programming Language & Translators, where I implemented a Test Suite for validating the KFrog Language interpreter.

Report: http://docs.google.com/viewer?url=http://gauravpandey.webs.com/KFrog_FinalProjectReport.pdf

Technical details: https://docs.google.com/View?id=d8gtx9j_164g2gz7k5x

Originally, the idea was to test the graphical output generated by the interpreter. Since, it was JVM dependent we assumed that Java would produce the correct graphical output as long as our interpreter correctly interpreted the given program. Thus, the focus shifted to testing the semantics (grammar) of the language. To accomplish this, we decided of having an intermediate language which would be the de facto representation for debug messages and expanded-gold statements. My general strategy to semantic testing was a 4-step approach as outlined below:

Step 1 involved delving into the gold standard representation format. I had to come up with a format which would enable a tester to perform testing in the simplest possible way.  To that end we decided that a Web based markup language related representation would be ideal. HTML was chosen as the representative language for our gold standard representation of Test Cases.

   1:  <pond xsize="" ysize="" color="">
   2:  <frog id="">
   3:  </center>
   4:  </startdraw>
   5:  <loop value="">
   6:  </action type="" value="">
   7:  </action type="" valuemin="" valuemax="">
   8:  </curve type="" radius="" degree="">
   9:  </curve type="" radiusmin="" radiusmax="" degreemin="" degreemax="">
  10:  </goto xvalue="" yvalue="">
  11:  </goto xvaluemin="" xvaluemax="" yvaluemin="" yvaluemax="">
  12:  </loop>
  13:  </stopdraw>
  14:  </frog>
  15:  </pond>

In Step 2, we fetch the debug messages generated by the Interpreter by passing the parameter –test-semantics. This enables us to generate a .debug file which is a true mapping of the graphics generated on the screen. The following is a typical set of debug statements for generating a square of side 100.

   1:  pondsize 300,300
   2:  pondcolor WHITE
   3:  1 new Frog {
   4:  1 center
   5:  1 frogcolor BLUE
   6:  1 speed 3
   7:  1 startdraw
   8:  1 forward 100
   9:  1 turnleft 90
  10:  1 forward 100
  11:  1 turnleft 90
  12:  1 forward 100
  13:  1 turnleft 90
  14:  1 forward 100
  15:  1 turnleft 90
  16:  1 stopdraw
  17:  1 }

In Step 3, we formulate the test cases which are capable of testing a specific subset of the language all at once. The following is a gold standard representation for generating a square of length 100

   1:  <pond xsize="400" ysize="400" color="white">
   2:  <frog id="1">
   3:  </center>
   4:  </startdraw>
   5:  <loop value="4">
   6:  </action type="forward" value="100">
   7:  </action type="turnleft" value="90">
   8:  </loop>
   9:  </stopdraw>
  10:  </frog>
  11:  </pond>

In step 4, we utilize the Tester program which fetches the content of .debug and .gold file and populates 2 data structures (Vectors). The data stored in the data structures is in an Intermediate Format. In turn, both data structures are compared for exactness and a final response is provided – ‘PASS’ or ‘FAIL’. The following diagram shows the entire process in detail:


 
0  

Technical Certifications are like a TAX!

Just like many other Software Developers and Network Administrators, I was wondering whether Certifications in a particular technical domain will be advantageous in a way. Microsoft, Cisco, Oracle, Red-Hat and countless others have their own set of certifications to assess, evaluate & justify a candidate’s skill set. But to be honest, ‘Certifications are like TAX on Software Developers’. Certifications are pretty easy to obtain and a candidate needs to simply go over some question bank or set of dumps available all over the Web! Most of them do not have practical evaluation and so, fall out of place.

Obtaining a specialized degree in Computer Science/Engineering would be far more valuable instead of getting certified! Hiring managers would actually look for experience in using a particular technology. For more info, read this.

0