initialization from incompatible pointer type

Discussion in 'C Programming' started by Brian Stubblefield, May 25, 2004.

  1. Dear clc members,

    I am rather new to the C programming language.

    I have a rather large program that I am currently debugging.

    Currently, the following snippet of code in the c program:

    char skillkey[96][1];
    char (*fillkey_ptr)[96]= skillkey;

    results in a "warning: initialization from incompatible pointer type"
    message during the compile.

    What can I do to solve this issue?

    Any help is greatly appreciated.

    Thank you in advance,

    Brian
     
    Brian Stubblefield, May 25, 2004
    #1
    1. Advertising

  2. Brian Stubblefield

    Karthik Guest

    Brian Stubblefield wrote:
    > Dear clc members,
    >
    > I am rather new to the C programming language.
    >
    > I have a rather large program that I am currently debugging.
    >
    > Currently, the following snippet of code in the c program:
    >
    > char skillkey[96][1];
    > char (*fillkey_ptr)[96]= skillkey;
    >
    > results in a "warning: initialization from incompatible pointer type"
    > message during the compile.


    >
    > What can I do to solve this issue?
    >
    > Any help is greatly appreciated.
    >
    > Thank you in advance,
    >
    > Brian


    On most linux systems, you have something called a 'cdecl' utility.
    That could be a real boon to know what the declarations really mean, at
    least to begin with.

    $ cdecl

    cdecl> explain char skillkey[96][1]
    declare skillkey as array 96 of array 1 of char

    cdecl> explain char (*fillkey_ptr)[96]
    declare fillkey_ptr as pointer to array 96 of char


    So essentially you are trying to assign two totally unrelated quantities.



    #include <stdlib.h>

    int main() {
    char skillkey[96];
    char (*fillkey_ptr)[96];
    fillkey_ptr = &skillkey;
    return EXIT_SUCCESS;
    }

    This code compiles perfectly fine.

    But you need to ask yourself the objective of the declaration and its
    usage.

    HTH

    --
    Karthik.
    Humans please 'removeme_' for my real email.
     
    Karthik, May 25, 2004
    #2
    1. Advertising

  3. Brian Stubblefield

    Eric Sosman Guest

    Brian Stubblefield wrote:
    > Dear clc members,
    >
    > I am rather new to the C programming language.
    >
    > I have a rather large program that I am currently debugging.
    >
    > Currently, the following snippet of code in the c program:
    >
    > char skillkey[96][1];
    > char (*fillkey_ptr)[96]= skillkey;
    >
    > results in a "warning: initialization from incompatible pointer type"
    > message during the compile.
    >
    > What can I do to solve this issue?


    First, read Section 6 of the comp.lang.c Frequently
    Asked Questions list

    http://www.eskimo.com/~scs/C-faq/top.html

    to make sure you understand the differences between
    pointers and arrays. Second, study the rest of the
    program to try to divine the author's incorrectly-
    expressed intent. Third, try to write a correct
    expression of that intent; this may well require
    changes outside the two lines you've shown.

    Do *not* try to "solve" the problem by adding
    a cast operator. That's like "fixing" your car's
    oil pressure warning light by putting tape over it.

    --
     
    Eric Sosman, May 25, 2004
    #3
  4. Thank you both for the suggestions. I am glad that I was told both
    where to look to find out more about pointers and arrays as well as a
    code solution.
     
    Brian Stubblefield, May 27, 2004
    #4
    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. Chris Readle

    Passing arg from incompatible pointer type

    Chris Readle, Jun 20, 2004, in forum: C Programming
    Replies:
    15
    Views:
    24,986
    Dan Pop
    Jun 24, 2004
  2. Josh Wilson

    tmpnam, strcpy - incompatible pointer type?

    Josh Wilson, Jun 21, 2004, in forum: C Programming
    Replies:
    1
    Views:
    3,801
    Eric Sosman
    Jun 21, 2004
  3. Replies:
    2
    Views:
    1,150
    Ian Collins
    Jul 26, 2006
  4. Replies:
    0
    Views:
    1,016
  5. Replies:
    1
    Views:
    498
    Andrew Poelstra
    Jul 26, 2006
Loading...

Share This Page