Sunday, February 28, 2010

Dreaming in code....

Past two weeks have been really tough since I have been putting in almost 10 - 12 hours of work (C programming) almost every day. My project is at the stage of completion and we are currently conducting extensive reviews. As usual there are last moment issues to resolve and the time is really short....When I am not working, I am usually "dreaming in code".

Labels: , ,

Saturday, October 11, 2008

ADT in C

Abstract Data Type in C

Labels: ,

Tuesday, August 19, 2008

Difference between __cdecl and __stdcall

The Microsoft compiler offers two calling coventions one __cdecl (Standard C calling convention) and the other __stdcall. All of the windows system calls are implemented using the __stdcall calling convention.

In case of __cdecl
1) It is possible to pass a variable argument (parameter) list (Standard C requirement)
2) As a result the calling function is suppose to clean up the arguments (parameters) of the stack. Since it is just the calling function which knows the exact number of argument bytes.

In case of __stdcall
1) It is not possible to pass a variable argument (parameter) list
2) As the number of arguments are known at compile time, it is possible to pass the information regarding the number of parameters on the stack to the called function. The called function can then itself perform the stack cleanup before returning.

As a result the __stdcall results in a more compact code since the called function performs the stack cleanup instead of each calling function doing it, there by saving few bytes per calling function. There by making the code tiny bit faster as well.

Labels:

Unixwiz

A Unix Wiz

Labels: ,

Sunday, August 17, 2008

Systems programming

A good basic Systems Programming course.

Labels:

Tuesday, August 12, 2008

C Programming FAQ

A good C Programming FAQ

Labels:

Saturday, August 02, 2008

Avoid macros in C

Macros in C are problematic. This explained via example as follows

#define CHECK_INT(x) (x != 10 && x >= 20 && x <= 100)
while (CHECK_INT(val = get_value_from_void() )) {
....
}

Now the problem occurs when x inside the problem fails a check. Each time a check fails, get_value_from_void is called again to get a new value of x.

Hence be careful while using macros in C. Follow the rules given below to avoid problems
1) Make sure the argument to the macros are evaluated before passing them to the macro
2) Make sure to parenthise the macro body and it's arguments.
3) DO NOT use macro definitions to define constants in C, use enum instead

Labels:

Friday, August 01, 2008

Practice of Programming

Some nice pointers from this book

1) Use active verbs for defining functions
2) When writing an expression for an if statement, spell it out loud (in your mind) and check if you can grasp the meaning of it.
3) Negations are hard to understand and hence avoid them.

Labels: ,