Jump to content

C - gcc: assignment from incompatible pointer type

Go to solution Solved by Darko_Nerivar,

That's just a warning

Compiles just fine

foo@bar:~$ gcc -o test test.ctest.c: In function ‘main’:test.c:5:9: warning: assignment from incompatible pointer type [enabled by default]foo@bar:~$ ./testElement 1: 15Element 2: 20Element 3: 25Element 4: 30Element 5: 35

and this is what you get with clang:

foo@bar:~$ clang -o test test.ctest.c:2:5: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]    main(){    ^~~~test.c:5:9: warning: incompatible pointer types assigning to 'int *' from 'int (*)[5]' [-Wincompatible-pointer-types]    ptr = &arr;        ^ ~~~~2 warnings generated.

If you write 

 int *ptr = arr;

instead, than no errors or warnings

gcc -o incrementing_pointers incrementing_pointers.c incrementing_pointers.c: In function ‘main’:incrementing_pointers.c:5:9: warning: assignment from incompatible pointer type [enabled by default]     ptr = &arr;         ^
#include <stdio.h>main(){    int arr[5] = {15, 20 , 25, 30, 35};    int *ptr;    ptr = &arr;    int i;    for(i = 0; i < 5; i++){        printf("Element %d: %d\n", i + 1, *ptr);        ptr++;    }}

I'm having an issue with compiling this code. 

I've been following along with a tutorial series and I've typed it character for character, but I don't seem to be able to get this to compile.

Here's the tutorial I've been watching:

export PS1='\[\033[1;30m\]┌╼ \[\033[1;32m\]\u@\h\[\033[1;30m\] ╾╼ \[\033[0;34m\]\w\[\033[0;36m\]\n\[\033[1;30m\]└╼ \[\033[1;37m\]'


"All your threads are belong to /dev/null"


| 80's Terminal Keyboard Conversion | $5 Graphics Card Silence Mod Tutorial | 485KH/s R9 270X | The Smallest Ethernet Cable | Ass Pennies | My Screenfetch |

Link to comment
Share on other sites

Link to post
Share on other sites

That's just a warning

Compiles just fine

foo@bar:~$ gcc -o test test.ctest.c: In function ‘main’:test.c:5:9: warning: assignment from incompatible pointer type [enabled by default]foo@bar:~$ ./testElement 1: 15Element 2: 20Element 3: 25Element 4: 30Element 5: 35

and this is what you get with clang:

foo@bar:~$ clang -o test test.ctest.c:2:5: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]    main(){    ^~~~test.c:5:9: warning: incompatible pointer types assigning to 'int *' from 'int (*)[5]' [-Wincompatible-pointer-types]    ptr = &arr;        ^ ~~~~2 warnings generated.

If you write 

 int *ptr = arr;

instead, than no errors or warnings

Link to comment
Share on other sites

Link to post
Share on other sites

-snip-

 

You beast you! :3

export PS1='\[\033[1;30m\]┌╼ \[\033[1;32m\]\u@\h\[\033[1;30m\] ╾╼ \[\033[0;34m\]\w\[\033[0;36m\]\n\[\033[1;30m\]└╼ \[\033[1;37m\]'


"All your threads are belong to /dev/null"


| 80's Terminal Keyboard Conversion | $5 Graphics Card Silence Mod Tutorial | 485KH/s R9 270X | The Smallest Ethernet Cable | Ass Pennies | My Screenfetch |

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×