warning: assignment makes integer from pointer without a cast

D

Dawn Minnis

Hi

When I compile my files I get the following:

driver.c: In function `main':
driver.c:49: warning: assignment makes integer from pointer without a
cast
driver.c:50: warning: assignment makes integer from pointer without a
cast
driver.c:51: warning: assignment makes integer from pointer without a
cast
getparams.c: In function `getparams':
getparams.c:8: warning: assignment makes pointer from integer without
a cast

lines 49, 50 and 51 in driver refer to the lines
m = params[0];
n = params[1];
k = params[2];

and line 8 in getparams refers to the line
params[x] = atoi(argv[val]);

Can someone tell me why I'm getting this error message and how to fix
it. Needless to say, the program when ran from command prompt as for
example:
./test.o n y 4 5 6
does produce the desired output.

Please help find the problem thats causing the error.
Kind regards
Dawn

A cut down version of my main driver.c file looks like this:

#include <stdio.h>
#include <stdlib.h>

extern void getparams(int argc, char *argv[], int *params[]);

int main(int argc, char *argv[])
{
int c, m, n, k, lda, ldb, ldc;
int *params[10];

if(argc > 1)
{
/*Run getparams*/
getparams(argc, argv, params);

m = params[0];
n = params[1];
k = params[2];

printf("m= %i", m);
printf("n= %i", n);
printf("k= %i", k);

}

return 0;
}


My getparams.c file looks like this:

void getparams(int argc, char *argv[], int *params[])
{
int val=2, x=0;

for(val=2; val<argc; val++)
{
params[x] = atoi(argv[val]);
x++;
}
}
 
E

Emmanuel Delahaye

Dawn Minnis wrote on 20/02/05 :
#include <stdio.h>
#include <stdlib.h>

extern void getparams(int argc, char *argv[], int *params[]);

int main(int argc, char *argv[])
{
int c, m, n, k, lda, ldb, ldc;
int *params[10];

An array of pointers ? Is it really what you want? I guess that what
you actually want is:

int params[10];

Same here:
void getparams(int argc, char *argv[], int *params[])

void getparams(int argc, char *argv[], int params[])

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Mal nommer les choses c'est ajouter du malheur au
monde." -- Albert Camus.
 
K

Kenny McCormack

Hi

When I compile my files I get the following:

driver.c: In function `main':
driver.c:49: warning: assignment makes integer from pointer without a
cast
driver.c:50: warning: assignment makes integer from pointer without a
cast
driver.c:51: warning: assignment makes integer from pointer without a
cast
getparams.c: In function `getparams':
getparams.c:8: warning: assignment makes pointer from integer without
a cast ....
#include <stdio.h>
#include <stdlib.h>
extern void getparams(int argc, char *argv[], int *params/*[]*/);
int main(int argc, char *argv[])
{
int c, m, n, k, lda, ldb, ldc; int /***/params[10];

if(argc > 1)
{
/*Run getparams*/
getparams(argc, argv, params);

HTH.
 
M

Martin Ambuhl

Dawn said:
Hi

When I compile my files I get the following:

driver.c: In function `main':
driver.c:49: warning: assignment makes integer from pointer without a
cast
driver.c:50: warning: assignment makes integer from pointer without a
cast
driver.c:51: warning: assignment makes integer from pointer without a
cast
getparams.c: In function `getparams':
getparams.c:8: warning: assignment makes pointer from integer without
a cast

lines 49, 50 and 51 in driver refer to the lines
m = params[0];
n = params[1];
k = params[2];

Look at your declarations:
int c, m, n, k, lda, ldb, ldc;
int *params[10];

m, n, and k are declared as ints, the elements of params are
pointers-to-ints. Why are you doing this silly thing?
Needless to say, the program when ran from command prompt as for
example:
./test.o n y 4 5 6
does produce the desired output.

The above is bullshit. The "needless to say" is flat wrong. Storing
ints in pointers is not something that "needless to say" produces the
desired output.

Just get rid of all those extra '*'s:

#include <stdio.h>
#include <stdlib.h>

extern void getparams(int argc, char *argv[], int params[]);
/* mha: removed bogus '*' */

int main(int argc, char *argv[])
{
int m, n, k;
int params[10]; /* mha: removed bogus '*' */

if (argc > 1) {
/* Run getparams */
getparams(argc, argv, params);

m = params[0];
n = params[1];
k = params[2];

printf("m= %i", m);
printf("n= %i", n);
printf("k= %i", k);

}
putchar('\n'); /* mha: added. Without this '\n'
ending the last line of output, your
program does not have predictable
behavior */

return 0;
}


void getparams(int argc, char *argv[], int params[])
/* mha: removed bogus '*' */
{
int val = 2, x = 0;

for (val = 2; val < argc; val++) {
params[x] = atoi(argv[val]);
x++;
}
}
 
D

Dawn Minnis

Wow

You couldn't half tell I don't know what I'm talking about half the
time. That worked. Thank you so much for that. Thats all it took to
get rid of the warnings and perform a clean compile.

Thanks ever so much. It's been bugging me for days now.

Dawn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top