Monday, February 7, 2011

When properties screwed up

When Properties got screwed up in Visual Studio 2005/2008, in the cmd, type "devenv /resetskippkgs".
It will get you the default properties (color, font etc) for your editor. 

Wednesday, August 25, 2010

Late/Dynamic Binding in C++






Late Binding using Function Pointers (C)

Tuesday, August 24, 2010

Locks in Multi-processing/multi-thread programming

DeadLock:
deadlock is a situation wherein two or more competing actions are each waiting for the other to finish, and thus neither ever does.


LiveLock:

livelock is similar to a deadlock, except that the states of the processes involved in the livelock constantly change with regard to one another, none progressing. Livelock is a special case of resource starvation; the general definition only states that a specific process is not progressing.
A real-world example of livelock occurs when two people meet in a narrow corridor, and each tries to be polite by moving aside to let the other pass, but they end up swaying from side to side without making any progress because they both repeatedly move the same way at the same time.
Livelock is a risk with some algorithms that detect and recover from deadlock. If more than one process takes action, the deadlock detection algorithm can repeatedly trigger. This can be avoided by ensuring that only one process (chosen randomly or by priority) takes action.

I2C protocol

http://www.i2cbus.com/theprotocol.html

new/delete operator

1. Return type of delete operator is void (not void*)




2. Exception and valid cases


char *p;
delete p; ==> exception (shown in picture)




Where as
char *p = 0;
delete p; .==> You can, however, use delete on a pointer with the value 0. This provision means that, when newreturns 0 on failure, deleting the result of a failed new operation is harmless.




2. Mixing both new/malloc and delete/free


class A {
public:
   A() { cout << "Constructor" << endl;
   ~A() { cout << "Destructor" << endl;
};


int main() {
  A *a = new A;
  free(a);                 ==> Calls only constructor; not destructor


 A *b = (A*)malloc(sizeof(A));
 delete b;               ==> Calls only destructor; not constructor


 A *c = new A;
 delete c;                ==> Calls both constructor and destructor
}                          



Monday, June 21, 2010

GDB unknown commands

All in gdb> prompt

1. Ctrl + p => To get the previous command
2. p array@sizeof(array) => To print all the array elements
3. set print pretty on => To print the structure elements' values in a neat way
4. p /x => prints the value in hexa decimal format

Tuesday, March 30, 2010

VI keyboard Shortcuts

:set hlsearch (:nohl)

:set mouse=a

:set nocompatible

:set smartindent
:set nowrapscan (to disable the wrap search)

:highlight String ctermfg=red

:highlight search ctermfg=black


  • To indent a block of code, keep the cursor in any of the {} braces, and do =%
  • To comment a block of line, keep the cursor in the first line (from where you want to comment), 
          - press CTRL + v (to enter visual mode)
          - use UP DOWN arrows (or j/k keys) to select the lines
          - press I (shift + i) (this enters into visual mode)
          - type "//" 
          - Once you press ESC, the // will be applied to all the lines you selected.
  • To uncomment a block of code, keep the cursor in the first line (from where you want to uncomment)
          - press CTRL + v (to enter visual mode)
          - select RIGHT LEFT arrows to select only the "//" characters
          - press "d" (to delete all the // characters)
  • To search and replace a text ("src" to "dest"), use
          :%s/src/dest/ ==> Replaces first occurence of "src" in each line
          :%s/src/dest/g ==> Replaces all the occurences of "src" with "dest" in all the lines
          :%s/src/dest/gc ==> Asks for confirmation to replace or not for each occurence


  • Vimdiff commands:
    • ]c - to go to the next change
    • [c - to go to the previous change
    • do - diff obtain; means get the changes from other file
    • dp - diff put; means put the changes into other file