Monday, January 30, 2012

Convert Date to MJD format


unsigned short int  VN_ConvertDate_to_MJD(unsigned short int ui16Day, unsigned short int  ui16Month, unsigned short int  ui16Year)
{
if(ui16Month<3)
{
    --ui16Year;
    ui16Month+=12;
}

ui16Year+=4800;
ui16Month-=3;

        return (ui16Year*365) +(ui16Year/4) + (30*ui16Month) +(ui16Month*3+2) / 5 + ui16Day -  
        7265/*32083 - 24817*/;
}

MJD - Modified Julian Date.

Friday, January 27, 2012

Segmentation violation & Bus error


Explain the meaning of "Segmentation violation".
A segmentation violation usually indicates an attempt to access memory which doesn't even exist.

What is "Bus error"?
A bus error indicates an attempt to access memory in an illegal way,perhaps due to an unaligned pointer.

Tuesday, January 17, 2012

Resolving warning: cast to pointer from integer of different size

'cast to pointer from integer of different size' This warning message will come while converting in to 64 bit from 32bit..

void *ptr = (void *)myVal;

This declaration gives ' cast to pointer from integer of different size ' warning..

intptr_t or uintptr_t are preferred to resolve this issue.

void *ptr = (void *)(intptr_t) myVal; // This declaration will avoid the warning Msg.


Monday, January 16, 2012

Resolving Warning: warning: deprecated conversion from string constant to ‘char*’

char *s = "hello";
This declaration will give the below warning message
warning: deprecated conversion from string constant to ‘char*’
 
To resolve this use declaration as follows,
 
char *s = (char *) "hello";

Sunday, January 15, 2012

Little endian to big endian

//2-byte number
int SHORT_little_endian_to_big_endian( int i)
{
    return (( i>>8)&0xff)+((i<<8)&0xff00);
}
//4-byte number
int INT_little_endian_To_big_endian(int i)
{
    return((i&0xff)<<24)+((i&0xff00)<<8)+((i&0xff0000)>>8)+((i>>24)&0xff);
}

Difference between memcpy and memmove

memmove offers guaranteed behavior if the source and destination arguments overlap. memcpy makes no such guarantee, and may therefore be more efficiently implementable. When in doubt, it's safer to use memmove.