I wrote a code and it compiles perfectly in CodeBlocks 13.12 with no errors ! i copied the same code to VS2010 it shows 1 error:
IntelliSense: identifier "malloc" is undefined
CodeBlocks Code:
#include <stdio.h>
#define maxLength 4
typedef short int *set;
void func(set *a)
{
*a=malloc(maxLength*sizeof(set));
(*a)[0]=10;
(*a)[1]=13;
(*a)[2]=15;
}
void main()
{
set a;
func(&a);
printf("%d %d %d",a[0],a[1],a[2]);
}
VS2010 Code:
#include "stdafx.h"
#include <stdio.h>
#define maxLength 4
typedef short int *set;
void func(set *a){
*a=malloc(maxLength*sizeof(set));
(*a)[0]=10;
(*a)[1]=13;
(*a)[2]=15;
}
int _tmain(int argc, _TCHAR* argv[])
{
set a;
func(&a);
printf("%d %d %d",a[0],a[1],a[2]);
return 0;
}
I don't know what is the problem ..
and if i add in the pre-compile code : #include <iostream>
the error goes , but another error appears:
IntelliSense: a value of type "void *" cannot be assigned to an entity of type "set"
NEW CODE
void func(set *a){
func(a);
}
void func1(set *a){
*a=reinterpret_cast<set>(malloc(maxLength*sizeof(set)));
(*a)[0]=10;
(*a)[1]=13;
(*a)[2]=15;
}
How do i create an array in a function that called by a function ?