Monthly Archive for November, 2008

Variadic Functions

C is a beautiful language. Though I have been using it for a few years now, I have yet completely mastered it. Just now, I stumbled across what are called variadic functions.

Have you ever wondered how to write functions that take in variable numbers or arguments? Take for instance printf() or scanf(). Both have been implemented in C. These are called variadic functions.

Problem: To construct a function which can take variable number of inputs, eg; printf()

Solution:

Its a simple matter of using built in macros defined in the stdarg.h library. It provides the following macros:

  • va_list: The list of argument
  • va_start: Initializes va_list to the first unnamed argument
  • va_arg: Takes the current variable and the type
  • va_end: Called at the end

Through a self explaining example I would like to demonstrate the usage of these macros. Let us define a new function called PBAPrint() which imitates the printf() function.  For example,

PBAPrint(“df”, 12, 2.2) outputs: int = 12 float = 2.2

PBAPrint is implemented as follows:


void PBAPrint(char *format, ...) {
  va_list ap;

  va_start(ap, format);

  while(*format) {
    if(*format == 'd')
      printf("int = %d ", va_arg(ap, int));
    else if(*format == 'f')
      printf("float = %f ", va_arg(ap, float));
    else {
      printf("unsupported format ");
      break;
    }
    format++;
  }

  va_end(ap);

  return;
}

But apparently things are much more simpler when using C++.

Popularity: 3% [?]

And So It Begins …

Finally the time has come when the students of IIT’s dress up in white shirts, black pants, a pair of black shoes and put on a tie. Yup, its the placement time, starting in a couple of days. Everybody glued to the TnP website, eagerly waiting for the shortlists to be put up.

I have already given 5 tests in the build up – Morgan Stanley, Inductis, Capital One, JP Morgan and Oracle. Sadly, rejected in Morgan Stanley and JP Morgan after clearing the first rounds in each. Not much regrets.

And a lot of preliminary tests to follow still. I already have two tests scheduled at the end of each day till the fourth of December! Its going to be one hell of a hectic week, unless I get placed somewhere :) .

So with fingers crossed, here I am, ready for the placemnets. Hope it end as soon as it begins.

Popularity: 1% [?]

Ultraspeed GPL

It was Ratno’s birthday a couple of days ago. As usual the traditional GPL and cake cutting followed. This time though, there was also an additional treat. A practise we have long stopped following. Since the exams were going on, we could not go to VS canteen, however an hour spent at Srivastava was as good as you get. The treat is due yet.

I am posting the photos from his birthday celebrations below.

Popularity: unranked [?]

Abominable Graph Theory

The worst day ever it was. It started off with me falling asleep studying for the AGT exam. I had almost given up on the paper, but I admit, I did not put in any extra efforts to study. Then the match started, India vs. England, third ODI at Kanpur – another distraction.

Now panic started creeping in, what with most of the syllabus left and only four hours until the exam. And yet studying was out of question, the temptation to run away too great to ignore. I ended up half studying, half day dreaming.

Finally the exam began. The usual routine – mind goes blank, seconds hand slows down, the writing seems greek and nothing goes right for the next three hours. After the exam, the usual discussions, everyone complaining how tough the paper was, how much they missed out on and how could it not have been not more worse. But at the end of it all, when you get back to your room, life feels good – even if it be only for a few hours though.

I need to get my concentration back. I have two tough exams on consecutive days lined up and I cannot stop myself watching Scrubs. But before I get started there is more important business to attend to. Its Ratno’s birthday gpl in about 10 minutes. Catch you later.

PS : I got a B in this subject, and am pretty happy about it, what with AG threatening a poor grade.

Popularity: 1% [?]

Role Playing

I have never really understood the human nature – the desire to feel wanted, connected with people all around, the need to socialise and above all to feel loved.

I sometimes feel that I am witnessing a phenomenon from some third persons’ view. I look at people making friends, and then trying everything to maintain the friendship. A lot of it actually being role playing. After giving the subject a lot of thought, I have come to the conclusion that role playing is an important part of building relationship, simply because we don’t have much to talk about and so need an artificial topic to keep the conversation going, to prevent that awkward silence from creeping up.

Role playing can be observed among all age groups. We start as kids, playing part of our heroes, acting like superman or whoever we idolise. The next phase involves our friends too, each taking up their part – a few heroes and a few villains to keep the story going. And finally as we grow up, we imagine scenarios and debate what we would have done. All the time, the emphasis is on leaving behind the world of reality and venturing into an unknown world, perhaps to get to know your friend better.

And yet, I am unable to connect to this form of communication. I feel detached from the social obligations, they over burden my existance. I wonder if life could be simpler, if talking to friends only when there is something to talk about without straining the friendship could really work out.

I have been watching a lot of Dexter these days. I love the show, primarily because it centers around a psychotic who has to fake his emotions and keep up his appearance as a socially-responsible person.

I must now get back to my exam preparations – have Applied Graph Theory tomorrow, and haven’t yet started.

Popularity: 1% [?]

'appy budday Tambi

Belated birthday wishes for u, if u ever get to read this – which is highly improbable even by a long shot :) . But it is not with him that I wish to communicate here, its you guys (so what does this statement imply in the case of tambi ?).

Let me start by lettting u all know that Raunaq came of age this week on the 5th. The occasion was well celebrated with some good old style gpl, and cake cutting. But ofcourse, this was Tambi and something had to be special. A cake splash in the face was the need of the hour. Tambi must have surely remembered Chandan – his first bday at CTE.

I am embedding the bday pics over here.

Yo Baby Love, once again happy bdday :)

Popularity: 1% [?]