Title: Error: making pointer from integer in C
Tags: c;pointers;compiler-errors;int;mpi
Question: I am trying to write a c program thatwill check in a parallel way if a random vector is sorted or not.
int isSorted(int size, int array[]) {
.........
int *sub_rand_nums = (int *)malloc(sizeof(int) * num_elements_per_proc);
int orden = isSorted(num_elements_per_proc, sub_rand_nums);
// Gather all partial results to all the processes
int *sub_ordens = NULL;
if (my_rank == 0) {
int  *sub_ordens = (int *)malloc(sizeof(int) * my_size);
if (a == 0) {
int orden = isSorted(sub_ordens, my_size);
Can somebody help to solve teh problem with my code? It gives me the error of
passing argument 1 of ‘isSorted’ makes integer from pointer without a cast [-Wint-conversion]
orden = isSorted(sub_ordens, my_size);
passing argument 2 of ‘isSorted’ makes pointer from integer without a cast [-Wint-conversion]
orden = isSorted(sub_ordens, my_size);
Comment: `sub_ordens` is an `int *` (an integer pointer). You declared `isSorted` to accept an `int` as its first argument. Looks like you just swapped the arguments around. You declared `isSorted` to take first argument size, second argument array, but you call it with the array first followed by size second.

Here is the accepted answer: You declared int isSorted(int size, int array[]) which is saying that the first argument is an integer. Though later in the code you specify int *sub_ordens = NULL; which makes a pointer to an integer, but it is not itself an integer. To fix the first error you need to pass an integer to isSorted() instead of a pointer to an integer.
As for the second error, you did the opposite of what caused the first error. The int array[] is like saying int *array but you pass int my_size; which is an integer, not a pointer to an integer.
Stepping away from a technical aspect, let's think of this as something more tangible. You have two people, let's call them Person A and Person B. Person A holds a card with a number on it, Person B points to Person A, but Person B is not directly aware of the number written on the card. If the function wants a pointer, then you would look to Person B, but if it wants the number itself, you would look to Person A.
Your function is asking for a number (Person A) as the first parameter, and a pointer as the second parameter (Person B).
In the future, it would be easier to sort out if your code was a bit more uniform in presentation (spacing/style), and also if you remove the parts that are not directly related to the question.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:05/12/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c><pointers><compiler-errors><int><mpi>', 'Title': 'Error: making pointer from integer in C', 'ViewCount': 74, 'id': 50311460, 'user_AboutMe': None, 'user_AccountId': 13403489.0, 'user_DisplayName': 'Tester', 'user_Reputation': 449.0, 'user_Views': 75.0, 'user_id': 9672230.0}}