warning: assignment makes integer from pointer without a cast

Discussion in 'C Programming' started by Dawn Minnis, Feb 20, 2005.

  1. Dawn Minnis

    Dawn Minnis Guest

    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++;
    }
    }
     
    Dawn Minnis, Feb 20, 2005
    #1
    1. Advertising

  2. 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.
     
    Emmanuel Delahaye, Feb 20, 2005
    #2
    1. Advertising

  3. In article <>,
    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

    ....
    >#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.
     
    Kenny McCormack, Feb 20, 2005
    #3
  4. 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++;
    }
    }
     
    Martin Ambuhl, Feb 20, 2005
    #4
  5. Dawn Minnis

    Dawn Minnis Guest

    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
     
    Dawn Minnis, Feb 20, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rocke Robertson
    Replies:
    14
    Views:
    13,033
    Dan Pop
    Oct 2, 2003
  2. Markus Dehmann
    Replies:
    14
    Views:
    949
    Irrwahn Grausewitz
    Jun 28, 2004
  3. Replies:
    2
    Views:
    1,310
    Martin Ambuhl
    Apr 1, 2005
  4. Juggernaut
    Replies:
    10
    Views:
    1,665
    CBFalconer
    Apr 9, 2005
  5. Zach
    Replies:
    3
    Views:
    7,635
Loading...

Share This Page