Friday, 24 July 2015

A letter to my son on his 4th BirthDay.

Dear Aadi,

You turned 4 today. A very very happy birthday :-)

Past one year has been exciting. You are growing from a cute baby to a naughty toddler and I am loving every bit of it. I also got straight 10 months of continuous stay with you without having to move out of station for work. I know you would not remember these early days as you grow. Luck will have it and you may get to relive your childhood when your kid makes his way into the world. Every little mischief you make tells me how was I some 30 years ago. Though I sometimes do feel that I am too calm for all the tantrums you throw and you have significant share of genes from your mom. Yet you two are the best things that has ever occurred to me.

Your fourth year was eventful. Life has a unique communication methodology for its participants. It talks to us via canvases it paints and every move we make in reaction. Some works out and feels good. Some teaches the smarts required to enjoy it the next time. Allow me to redraw the theme of some of the those as I understood it. Perhaps it will prove out to you that life is actually a fun game. We need to play it smartly to win not in the end but during the game.


Your School
Till date you hate the mornings when we dress you up. You hardly smile from the point we wake you till you enter the classroom and sometimes you cry also. Per your class teacher, you are different person in the classroom. You play like there is no tomorrow, scream, run, beat, get beaten. I figured out that its the transition - leaving home and on the way to school, you hate not the school itself. We all have that anxiety. Leaving a comfort zone in anticipation of another comfort zone is a risk and we need to learn to take that calculated risk. These early transitions will make you believe in change and hope that eventually things end well. 

Stage Fear
I still remember the 4 lines I made you by heart on Mars Orbiter and the satellite model that we made for you to wear for school event.  Despite of having practiced for several days at home and in class; you went blank on -the- day. My numerous attempt of cheering from audience and forbearing master of ceremony couldn't get you going. Never mind; it happens.  That day I learnt an important lesson. You never signed up for doing everything right. Kids may fail parent's desire and I better be prepared to work harder the next time. I promise that I won't stop till the day you take the walk up to stage and say ... 'Hello Everyone, I am Adhrit....................'

Leg Fracture
You fractured your left leg in Chicago. I still hear that noise 'kdaak'. Your howl, tears, hospital, plaster all were so painful. We both cried that night. Things do go wrong at times. We must remember that whatever it is we will be past it. And till we are going through it, lets face with hope. Your grand father had told me once ... 'musibat se daro jab wo aane wali ho par jab wo aa hi jaye to himmat rakho aur samna karo. Rolo lekin date raho'. See we are past it. You faced it bravely son. Imagine, you a three year old kid consoling his father ... ' papa, theek ho jayega'

Younger Brother
You are a big bro now. As 'chota' stepped in few months ago. I am sorry that your 'one baby one mom/dad equation was proved wrong' and that I couldn't answer when you asked that where are his mummy/papa and why doesn't he go to his home. I like that you have an audience for the stunts you do and you would repeat those because it makes the baby laugh. Your unique way of caring for him but still not letting him play with your toys. I go to work, mom is busy too at work or making home but you have one special person who has all the time in world for you. You are lucky.


Your Papa.
Mitendra Anand
25th July, 2015

Chicago, USA



Milton Lee Olive Park, Chicago - June 13th 2015









Friday, 25 July 2014

A letter to my son on his 3rd BirthDay.



Dear Aadi,

You turned 3 today, and I still believe that most joyful moment of my life had happened just yesterday. When I was waiting outside of operation theater in hospital and a gentlemen popped after good 40 minutes of wait and said ‘Anushree Anand: I ran….almost fell …. Male Child, Born at 3:42 PM and Body Weight: 3.95 kg’

Your eyes were so wide open and you were looking all around. I couldn’t believe that you were just born, I so wanted to touch you, kiss you but was not granted. ‘Baby needs to be at nursery’ for 24 hours, came the rude voice. I said okay anything for my dear son. I can’t tell you how I felt when I took you in my arms. It seemed pretty technical to say the least, I mean hold in such way that your head is steady still not pressing you hard. All others were scared, and I was like champ without any practice. Of course where else would you be safest if not with me.

Life has changed since. Not very long ago I used to worry about my looks/career/comfort etc. Now whichever store I go, toys fascinates me, baby clothing, shoes are my latest interest. I am kid again and thank God for that and thank you for that.

I know you can’t read it now but one day you shall be. I am writing this letter so that you get a chance to read about your past days because it would feel so different and exciting. I never had this experience so I don’t know how it’d feel, well … will ask you when you are at it. There are few thoughts I would like to share with you on your birthday. These are nothing but some of my wishes which I could not pursue. Now that I have got another life in you I would like to re-do some of that.

Love a sport and pursue it.
As a kid I practiced cricket every day after school. I wasn’t best at it but not bad either. Besides keeping you fit and healthy at mind & body, sport is a wonderful distraction in life. It’s something which gives you every chance to not to think about things which are not in best shape at present. Sport also makes us disciplined in a sense that if you want to get better and then you need to practice certain rules/step on a regular basis. This will make you fighter and force you not to give up easily.

Be a part of musical world.
I am a good listener. I mean that’s the best I could do with music. I suggest you should pick up singing, I know singing is natural talent so one may or one may not but then at least learn to play an instrument. Mankind has always loved the entertainment breed. People who have the ability to sing or play are the core part of the same. They not only de-stress themselves but teach others that world is so beautiful and why not appreciate nature for what it has laid for us. Believe me mother nature did not make us to earn livelihood and break the bread. It had much better plans but we over thought her ideas.

Education is just part of life.
Yes, don’t take it too seriously. I say so because I took it seriously and tried to be best in every subject which was thrown on me . Today I DO NOT earn even a single penny out of those topics for which I burnt midnight oil all my teenage. I wish you better career and prospect than me but I seriously feel that science, mathematics, social science etc would not guarantee that. To be successful I think one just needs to know what he/she is best at and keep refining that. I know people spend 20 years to find one best area for them before they finally succeed. I wish you the same realistically but I want you to remember that ‘studies’ is not necessarily that area so keep your options open. Having said that you must go to school to become educated enough to decide on it.


Your Papa.
Mitendra Anand
25th July, 2014
Chicago, USA

P.S. : Forgive me for not being with you physically, as I said once “Iss do takiye ki naukri me mera lakhon ka bachpan jaye”.



Tuesday, 20 August 2013

Why ChennaiExpress clicked and OnceUponATimeInMumbai D didn't?

Both the movies are hopelessly useless but while  the former clicked the latter didn't. Here is my take on the matter. There were basically 4 aspects of one's failure and others success:- 

Story: ChennaiExpress has the story-line of worst kind. Hero is jobless, purposeless, 40+, can't fight the villain etc. etc. But the good thing with CE, Rohit Shettly was aware of no story. So he put his money on comic timing, fast sreenplay, car actions and colorful canvas. Basically he did not break the pattern, audience got the meal which they were expecting and had tasted before.
OUATMD borrowed its story from Mumbai, so it fairs better. But for stories like underworld you need real incidents so that people can correlate it with past and true picture of purpose not something like running behind love. Broken story is as worse as No Story. Even excellent one liners/ dialogs from Milan Luthria did not help.

Star Cast: Every single viewer is blaiming Imran Khan for OUATMD failure. Rightly so but the fault is not Imran's but the casting crew. Since when we get pink lipped goon? Not a big fan for Sonakshi Sinha either, she was lucky with Dabang her physique suited the character Rajjo, every where else she is a misfit. A lot was on shoulder of Akhsay Kumar and he did deliver in style.
CE has SRK, the biggie himself and Deepika, a better choice any day. 

Music: S P Balasubrahmanyam was a pleasant surprise in CE. The title song justifies the fast screenplay. Then the presence of foot number - 1 2 3 4 Get on the Dance Floor, melody - Titli, Yo Yo - Thalaiva were good addition to the package.
 OUATMD, only song you would remember when out of theatre will be Aiyo Balli ... Pyar ka Dushman. Which is not an original anyway. 

Marketing:  SRK is epitome of marketing products, he has taught bollywood how to do the same. Though he fell on face because of over marketing Ra.One, still looks like it worked this time. Ekta Kapoor should have come with some stepped up marketing for
OUATMD. She believed too much in Akshay's fan following.

Thursday, 15 August 2013

Why Modi scores over Mr. Singh?

As India celebrates it's 67th Independence Day, not sure if India has been really a democracy in the true terms. 1947 onwards, the opposition has had just one full term at the center. The first six decades of its democracy, the center has only seen a government led by a single party. More often than not, power corrupts over a period of time.

Till 80s, India was more successful than China. It was more successful than South Korea, more successful than most places in Asia. It is unfortunate that we have failed to take advantage of some of our most valuable assets. India has some of the smartest people in the world, but it does not have an education system to support it. Infrastructure is equally poor. There are millions of entrepreneurial, driven and smart Indians amongst us, but most of them want to be abroad because they know that unless they are involved with the right people in India, they are not going to be successful. Fewer than 50% of Indians stay in school till they graduate. There are very good Indian universities, but very few for the number of Indians who need good education.

There are not many successful Indian companies either, except those that are associated with the government. Look around in world and you won’t see many Indian products, except for some restaurants. There are very few Indian brands that are recognized outside India. Apart from a couple of software companies, none of the Indian firms have made it big in the international scene. Also, not to forget that the regulations that India puts in place result in foreigners going through nested loops before they can invest in India.

India should have been among the world’s greatest agriculture nations — given the soil, the human resource, the weather, but it is astonishing that we have not become one. It is because Indian politicians, in their wisdom, have made it illegal for farmers to own more than five hectares of land. Can a farmer with just five hectares compete with farmers in Australia or Canada?

As wisely said by Rogers Holdings chairman Jim Rogers , If the billion plus people in India demand more and say the current system that is going on since 1947 is absurd, then it might make India a whole lot better. Compared to many of the countries globally, India was on top in 1947, but relatively India has only declined since then. Remember that you move from dictatorship to oligarchy to democracy to chaos—may be they will throw out these absurd oligarchs who rule India and then it may have a vibrant democracy and regain its proper place, its historic place in the globe. 


आजादी का मतलब - अपने लक्ष्य और अधिकारों के प्रति जागरूक होना |

Monday, 12 August 2013

What C++ has in offer...

Speed: The language not only optimizes in terms of how you program but also makes optimal use of hardware cache. For Example, std::vector gets cached in processor irrespective of its size. Today's Processors come with rich inbuilt cache, let’s make best use of them.

Efficiency: Threading libraries and Parallel/concurrent programming helps in more throughput. In Financial sector the focus is on high demanding applications that need performance. The “king” is Performance per Watt, per Cycle, per Transistor: Performance per Dollar.

C++11: C++11 has a lot of new features. Soon we will use these Features in order to take advantage of new frameworks (like C++ AMP). “C++ matters again as a first class system” i.e. it provides choice at the user level for Windows, Mac OS X and Linux as well as a range of web user interfaces. Imagine the benefit of being able to support the Windows, Mac, and Linux users within your organization with a consistent, identical suite of services.

Alleged Non managed Language: Managed languages don’t have the performance, deployability or serviceability (among others) required to develop a Large Systems or Operating System. That’s why Windows nowadays is all C and C++ and will probably stay that way. The bottom line is that C++ is close to the metal, which means that everything in the execution is right in the code.

Error Proneness: C++ “language” doesn’t provide helpful black box functionality? If there was such a language that could prevent bugs in the software, we wouldn’t be having this discussion.  Everyone would switch.  Fact is, you can write bugs in any language.  When it comes down to the eleventh hour and the problem just has to be solved before I go home that night I need to be able to conveniently walking through every line of code in the debugger.  The so called helpful black box in coder friendly programming languages, that usually works, just becomes a nightmare then.  



In the end choice of language is more like choosing the right size hammer for the nail. For example, if I want to write a device driver for a hardware, I would go for C. If I want to write graphics intensive I would go for C++. If I want to write a new OS I would go for assembly and C. If I want to do text pattern matching and replacement, I would go for Perl/Python. If I want faster web development I would go for Java, PHP. If I want more interactive web page effects, I go for Javascript.

Saturday, 10 August 2013

COM connection point callback for a C++/CLI client

If you have to write interop code, should you use C# and P/Invoke, or should you use C++/CLI? The clients for a COM connection point server can be written in C++ and in C# managed code. Recently, I got a query about the possibility of a managed C++/CLI client for a COM connection point server. A search on the web gave many samples of C++ and C# managed code but none for a C++/CLI client. It is a topic of debate; refer to this blog. It says “With C++/CLI, you can use the API natively exactly like it's meant to be used, and then "expose" the code to the managed world via C++/CLI”. This motivated me to write an article on how to implement a COM connection point callback for a C++/CLI client.

Read More

C++ Interview Questions

Can a member function template be virtual?



Think about it for a while:

Q.1. How could you make a templated virtual function?
Q.2. What's its signature?
Q.3. How many vtable entries do you reserve?
Q.4. How would you distinguish between an override/hide and an overload?


Templates are all about the compiler generating code at compile-time. Virtual functions are all about the run-time system figuring out which function to call at run-time.

Once the run-time system figured out it would need to call a templatized virtual function, compilation is all done and the compiler cannot generate the appropriate instance anymore. Therefor, you cannot have virtual member function templates.

h<int>(&f<int>());


 

Making an API C Callable



A C++ function is not necessarily made C callable by prototyping the C++ function with the extern C keywords. While the extern C keyword prevents the name of the C++ from being mangled, there are other issues to be considered.

C vs C++ Issues

- C does not use classes. Therefore, it cannot pass classes by value. If a C++ API function requires that a class be passed by value as its input, it is not C callable, regardless of whether it is prototyped with the extern C keyword. This leads to the following rule: API functions must not pass classes by value.

- C does have "void pointers". A C void pointer points to the address of a class just as it points to a structure. Therefore, a C++ API function would be C callable if its class arguments were passed by address (BODY*) or by reference (BODY&). Either method allows the API function to be called from C.

 

What is difference between "new operator" and "operator new"?



The difference between the two is that operator new just allocates raw memory, nothing else. The new operator starts by using operator new to allocate memory, but then it invokes the constructor for the right type of object, so the result is a real live object created in that memory. If that object contains any other objects (either embedded or as base classes) those constructors as invoked as well.

Following is the quote from More Effective C++ book from Scott Meyers:

The new operator calls a function to perform the requisite memory allocation, and you can rewrite or overload that function to change its behavior. The name of the function the new operator calls to allocate memory is operator new.

 

Is there any way a C/C++ program can crash before main()?



There are many possibilities.

First, we need to understand what actually goes on before main is executed:

    Load of dynamic libraries
    Initialization of globals
    One some compilers, some functions can be executed explicitly

Now, any of this can cause a crash in several ways:

    the usual undefined behavior (dereferencing null pointer, accessing memory you should not...)
    an exception thrown > since there is no catch, terminate is called and the program end

It's really annoying of course and possibly hard to debug, and that is why you should refrain from executing code before main as much as possible, and prefer lazy initialization if you can, or explicit initialization within main.

Of course, when it's a DLL failing and you can't modify it, you're in for a world of pain.

 

What happens when you run a program?



On Windows, first the image is loaded into memory. The kernel analizes which libraries (read "DLL") it is going to require and loads them up too. Initialization of globals happen.

It then edits the program image to insert the memory addresses of each of the library functions it requires. These addresses have a space in the .EXE binary already, but they are just filled with zeros.

Each DLL's DllMain() procedure then gets executed, one by one, from the most required DLL to the last, like following an order of dependences.

Once all libraries were loaded and got ready, finally the image is started, and whatever happens now will depend on language used, compiler used, and the program routine itself.


Client request to run application
  ->Shell informs kernel to run binary
  ->Kernel allocates memory from the pool to fit the binary image into
  ->Kernel loads binary into memory
  ->Kernel jumps to specific memory address
  ->Kernel starts processing the machine code located at this location
  ->Kernel pops current location into an execution stack
  ->Kernel jumps out of current memory to a shared memory location
  ->Kernel executes code from this shared memory location
  ->Kernel pops back the last memory location and jumps to that address
  ->If machine code has stop
  ->Kernel releases memory back to pool

 

Where does static or non-static variables stay? I mean in memory. and, When are static or non-static variables initialized?



They can go wherever the compiler (or linker or loader) wants to put them in memory, the C and C++ standards don't mandate that level of detail. They only mandate the behaviour.

Typically, static members are initialised once, either on program startup (including at compile time so that they're simply loaded in an already-initialised state) or immediately before first use.

   


 

Difference between WinMain,main and DllMain in C++?



WinMain is used for an application (ending .exe) to indicate the process is starting. It will provide command line arguments for the process and serves as the user code entry point for a process. WinMain (or a different version of main) is also a required function. The OS needs a function to call in order to start a process running.

"DllMain" is used for a DLL to signify a lot of different scenarios. Most notably, it will be called when

    The DLL is loaded into the process: DLL_PROCESS_ATTACH
    The DLL is unloaded from the process: DLL_PROCESS_DETACH
    A thread is started in the process: DLL_THREAD_ATTACH
    A thread is ended in the process: DLL_THREAD_DETACH

DllMain is an optional construct and has a lot of implicit contracts associated with it. For instance, you should not be calling code that will force another DLL to load. In general it's fairly difficult function to get right and should be avoided unless you have a very specific need for it.

This is a good explanation ut it needs to also specify that these are required entry points for the three different types of "executables" (console app, windows app, windows DLL).

A DLL can run directly if you're using "rundll32.exe"

WinMain simply means that there will be NO console window allocated for the app, and its stdin and stdout have nowhere to go. All the guts of Windows API (such as event loop, registration of classes, window creation) still need to be done manually. Also, programs using main() can have windows too.

 

Return value optimization



The following example demonstrates a scenario where the implementation may eliminate one or both of the copies being made, even if the copy constructor has a visible side effect (printing text).[4] The first copy that may be eliminated is the one where C() is copied into the function f's return value. The second copy that may be eliminated is the copy of the temporary object returned by f to obj.

#include <iostream>

struct C {
  C() {}
  C(const C&) { std::cout << "A copy was made.\n"; }
};

C f() {
  return C();
}

int main() {
  std::cout << "Hello World!\n";
  C obj = f();
}

Depending upon the compiler, and that compiler's settings, the resulting program may display any of the following outputs:

Hello World!
A copy was made.
A copy was made.

Hello World!
A copy was made.

Hello World!

Background

Returning an object of builtin type from a function usually carries little to no overhead, since the object typically fits in a CPU register. Returning a larger object of class type may require more expensive copying from one memory location to another. To achieve this, an implementation may create a hidden object in the caller's stack frame, and pass the address of this object to the function. The function's return value is then copied into the hidden object.[5] Thus, code such as this:

struct Data {
  char bytes[16];
};

Data f() {
  Data result = {};
  // generate result
  return result;
}

int main() {
  Data d = f();
}

May generate code equivalent to this:

struct Data {
  char bytes[16];
};

Data * f(Data * _hiddenAddress) {
  Data result = {};
  // copy result into hidden object
  *_hiddenAddress = result;
  return _hiddenAddress;
}

int main() {
  Data _hidden; // create hidden object
  Data d = *f(&_hidden); // copy the result into d
}

which causes the Data object to be copied twice.

In the early stages of the evolution of C++, the language's inability to efficiently return an object of class type from a function was considered a weakness.[6] Around 1991, Walter Bright invented a technique to minimize copying, effectively replacing the hidden object and the named object inside the function with the object used to hold the result:[7]

struct Data {
  char bytes[16];
};

void f(Data *p) {
  // generate result directly in *p
}

int main() {
  Data d;
  f(&d);
}

Bright implemented this optimization in his Zortech C++ compiler.[6] This particular technique was later coined "Named return value optimization", referring to the fact that the copying of a named object is elided.[7]
[edit] Compiler support

Return value optimization is supported on most compilers.[1][8][9] There may be, however, circumstances where the compiler is unable to perform the optimization. One common case is when a function may return different named objects depending on the path of execution:[5][8][10]

#include <string>
std::string f(bool cond = false) {
  std::string first("first");
  std::string second("second");
  // the function may return one of two named objects
  // depending on its argument. RVO might not be applied
  return cond ? first : second;
}

int main() {
  std::string result = f();
}