initialization from incompatible pointer type

B

Brian Stubblefield

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
 
K

Karthik

Brian said:
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
 
E

Eric Sosman

Brian said:
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.
 
B

Brian Stubblefield

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.
 

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,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top