By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,873 Members | 1,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,873 IT Pros & Developers. It's quick & easy.

warning: assignment makes integer from pointer without a cast

P: n/a
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++;
}
}
Nov 14 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

Nov 14 '05 #2

P: n/a
In article <72**************************@posting.google.com >,
Dawn Minnis <da*********@gmail.com> wrote:
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.

Nov 14 '05 #3

P: n/a
Dawn Minnis wrote:
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++;
}
}

Nov 14 '05 #4

P: n/a
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
Nov 14 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.