Sunday, 24 February 2013

Right Shift of signed,unsigned char & int


Today ,I wrote a program for right shift of signed & unsigned int & char .Here we get some strange things.We need to understand it through program,Here is the snapshot of the program:-


Here we can see that signed char sc is different printed compare to inserted value.This is an anomaly.This is done because the the MSB is 1 But in case of signed char sc1 the printd value is same as inserted .This is because of value of MSB which is zero.In these if we take right shift of both we seen that In the case of  sc the value is unchanged because if we right shift the signed char or int it right shift the all bits & MSB equal to the MSB of original value either it is zero or one.In the case of unsigned char & int it right shift all the bits & MSB becomes Zero.These changes we can easily seen in the program.In the case of si & sc there is no change in right shift because MSB is one.  

Wednesday, 30 January 2013

Shift Operator (signed/unsigned)

Shift operator should be used very carefully .Because a little change in shift operator makes a major change in output.So it is very necessary to understand how it is internally work.Today I run a program which explains about shift operator .We need to take many signed & unsigned int & char variables.Then assign them some value.After performing right shift operation we conclude that the value of an integer become half of the previous value if we right shift the value by 1.Thus as we right shift by different values our previous value become half of its previous value.If we right shift a char say B by 1 which has a ASCII value 66 then it converts   char which has a ASCII value 33.The Same theory is applied to conversely applied to the right shift which double the previous value if we right shift by 1.If we right shift by 4 then it doubles the value 4 times .So It very useful in various opearation.    

Tuesday, 22 January 2013

Creating and using a DLL in C

Today I create a dll in C on microsoft visual studio 2010.Following are the snapshots of steps which we take during creating a dll in  microsoft visual studio 2010.








   After clicking finish we see several type of files in the project which are shown in below snapshot.


where temp is the name of project & cpp file.
In the temp.cpp file we need to write the definition of function & header files included in function writen in either temp.cpp or temp.h.Then we need to run which create temp.lib file in directory.By adding this temp.lib file into any project we easily use the dll only by adding used header in function into .h or .cpp file & calling the function.
we need to write __declspec (dllexport) for Cpp file & extern "C" __declspec (dllexport) for C file while creating library.



Here are some important keyword used in creating and using DLL:-

__declspec:-It is a storage class specifier .It uses various storage class attribute to enable various usage of it.

dllexport:-dllexport storage class attribute enables us to export function ,data & objects from the dll.Declaring function as dllexport eliminates the need for a module definition file ,at least with respect to the
specification of exported functions .Note that dllexport replaces the _export keyword .If a class is marked declspec (dllexport ),any specialization of class templates in the class hierarchy are implicitly marked as declspec(dllexport ).This means templates are explicitly instantiated and its member must be defined .The declaration of dllexport must use extended attribute syntax and the _declspec keyword.
Ex:-


__declspec( dllexport ) void func();


dllimport:-dllimport storage class attribute enables us to import function ,data & objects from the dll.The declaration of dllimport must use extended attribute syntax and the _declspec keyword.
Ex:-


__declspec( dllimport ) int i;

naked:-For the function declared with the naked attribute ,the compiler generates code without prolog and apilog code.Naked functions are particularly useful in writing virtual device driver.The naked code is only valid on x86 and is not available on x64 or itanium.
Ex:-


__declspec( naked ) int func( formal_parameters ) {}

Friday, 7 December 2012

Dynamic memory Allocation in 2-D Array


Today I wrote a program for dynamic memory allocation in 2-D array using malloc .We use  the 2-D  array as a 1-D .First of all we take a double pointer which stores the adress of a 1-D array.In this 1-D array we store the adresses of first location of each row.

Sunday, 25 November 2012

Compatibility of various bit application with Microprocessors & Operating System


There is various combinations of microprocessor,operating system & applications in which we can work.Some application are compatible on the some type of microprocessors & some type of operating system while some of them are not.With the help of above figure we can easily understand the problem.   

System configuration view




This is a simple system configuration view in which we have two sockets in each .We already know that there is many socket in a motherboard but each socket can have only one processor in it.Further,a microprocessor can have many cores.In this figure there are three systems all of them have two sockets & each socket have four cores.  

Thursday, 22 November 2012

Build Process

I draw a diagram to define the build process.How a program get executed in system & during this which type of files created & finally we get a executable file.