Let's hit the nomenclature first. It is not giving an error, it is a warning, a nonconformity warning that normally the compiler can pass, but it can cause problems ... in your case it will not cause. At least not because of the warning .
Explaining warning :
You have created a pointer to int ( int i, * vetor;
). When you access a pointer with the indexer, it "resolves" the pointer to its type, so you're trying to put a int*
type inside a int
variable.
Why did I say that this will not cause a problem?
- Because
int
has the same size in memory as int*
As I understand it from your code, you are trying to do a routine that returns a pointer to the allocated vector of type int with size X ... your routine has a number of conceptual problems:
You should do something like this:
int* aloca_vetor(int tamanho) {
return (int*)malloc( tamanho * sizeof(int) );
}
And then give a free
on the returned pointer when it will no longer be used.