P
pertheli
Hello all
What is the difference between Method 1 and Method 2 below? Is Method 2 safe to use?
typedef short Word;
typedef unsigned char Char;
int nAllocSize = large number;
//Method 1 crashes in my machine for large nAllocSize
Word* pShort = (Word*)malloc(nAllocSize*sizeof(Word));
//Method 2 seems ok even if nAllocSize is large
Word* pShort;
Char* pChar = (Char*)malloc(nAllocSize*sizeof(Char)*2);
pShort = (Word*)pChar;
What is the difference between Method 1 and Method 2 below? Is Method 2 safe to use?
typedef short Word;
typedef unsigned char Char;
int nAllocSize = large number;
//Method 1 crashes in my machine for large nAllocSize
Word* pShort = (Word*)malloc(nAllocSize*sizeof(Word));
//Method 2 seems ok even if nAllocSize is large
Word* pShort;
Char* pChar = (Char*)malloc(nAllocSize*sizeof(Char)*2);
pShort = (Word*)pChar;