• [RESOLVED] assignment from incompatible pointer type
  • User Interface (mTouch, HCVD, LCD)
  • Send to Recycle Bin
  • Delete Permanently

Use My Existing Forum Account

meaning of assignment from incompatible pointer type

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Assignment from incompatible pointer type

I'm not sure why this is happening, I think I'm doing everything correctly.. Maybe someone can help point me in the right direction.

These are spaced out in the program so I didn't want to copy a bunch of code but if more is needed please let me know.

Shouldn't this work correctly without giving me the incompatible pointer type?

Natan Streppel's user avatar

3 Answers 3

No, this should not work, because you're assigning an int* value to an unsigned short* variable, which causes undefined behavior per the C strict aliasing rule .

The way to make this work without changing the types is to

But really, I strongly recommend you change the types to be compatible, since otherwise you're tying yourself to a single compiler's extensions to the C standard.

Community's user avatar

and things are ok.

alk's user avatar

In your case x is a unsigned short pointer and textLeft is a signed integer. You are trying to assign signed integer address to unsigned short pointer.

Chinna's user avatar

Your Answer

Sign up or log in, post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service , privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged c linux unix or ask your own question .

Hot Network Questions

meaning of assignment from incompatible pointer type

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .

Hello, buddy!

I'm a coder. Welcome to my blog. Here are some of the records on my job.

Assignment from incompatible pointer type (structures, linked list).

Creating a dictionary data structure using a linked list.

Working on the function to add dictionary entries to the linked list.

assigning d->curr to d->curr->next gives me the warning 'assignment from incompatible pointer type'.

What is my mistake here? both curr and next are of the type *dictionary_entry_t

next is a struct dictionary_entry_t * , but d->curr is a dictionary_entry_t * aka struct _dictionary_entry_t * . Note the difference in underscores.

One way to solve this would be to be consistent with your underscores, declaring next as:

However, I prefer a different way: typedef fing before declaring the struct . Then:

Related Articles

Why do i get & ldquo; warning: assignment from incompatible pointer type [enabled by default] | & rdquo;, assigning an incompatible pointer type to c, & ldquo; warning: assigning an incompatible pointer type & rdquo; when using a double pointer, ignore & ldquo; initialization from incompatible pointer type & rdquo; warnings?, assignment by incompatible pointer type?, get & ldquo; warning: assigning an incompatible pointer type & rdquo;, the assignment from the incompatible pointer type in the linked list?, the assignment of the incompatible pointer type in the linked list (c), structure tree: assignment from an incompatible pointer type, assignment from the incompatible pointer type, caution: assign from an incompatible pointer type, warning: incompatible pointer type assignment [enabled by default], warning: assignment of an incompatible pointer type [enabled by default] when assigning the function address to the function pointer, compilation warning c: pass argument 1 of 'insert' from the incompatible pointer type [enabled by default].

ifelse.info

Website disabled, managed by virtualmin - a powerful and flexible web hosting control panel.

C Board

Home

warning: assignment from incompatible pointer type

Thread: warning: assignment from incompatible pointer type

Thread tools.

Search Thread

abhi143 is offline

I want to print name and age of person in program Code: #include <stdio.h>#include <stdlib.h> #include <string.h> typedef struct Person { char Name[20]; int Age; int *next; }List; int main() { List *head = NULL; head = (List*)malloc(sizeof(List)); head->Age = 20; strcpy(head->Name,"Abhi\n"); head->next = NULL; while(!head) { printf(" %d ",head->Age); printf(" %s ",head->Name); head = head->next; }; free(head); return(0); } warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] head = head->next; ^ What's wrong in the code ?

laserlight is offline

You declared next to be an int* instead of a struct Person*. Also, you should typedef the struct to either Person or Node, not List.
Originally Posted by Bjarne Stroustrup (2000-10-14) I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool. Look up a C++ Reference and learn How To Ask Questions The Smart Way
Originally Posted by laserlight You declared next to be an int* instead of a struct Person*. Also, you should typedef the struct to either Person or Node, not List. Now code compile without warning but It doesn't print name and age Code: #include <stdio.h>#include <stdlib.h> #include <string.h> typedef struct Person { char Name[20]; int Age; struct Person *next; }List; int main() { List *head = NULL; head = (List*)malloc(sizeof(List)); head->Age = 20; strcpy(head->Name,"Abhi\n"); head->next = NULL; while(!head) { printf(" %d ",head->Age); printf(" %s ",head->Name); head = head->next; }; free(head); return(0); }
Your while loop condition should be head, not !head. Actually, you shouldn't use head for this because you need it to keep track of the head of the linked list. Use another node pointer.

subscribe to a feed

Similar Threads

Warning: assignment from incompatible pointer type - drawing_area, warning: assignment from incompatible pointer type., [warning] incompatible pointer type, incompatible pointer type warning, warning: assignment from a incompatible pointer type, tags for this thread.

View Tag Cloud

assignment from incompatible pointer type

Member Avatar

I am getting a the warning "assignment from incompatible pointer type" when compiling my code, I have spent ages trying everything I can think of, but I am not very experienced at using C so it is probably something really simple that I just can't see.

I have commented the lines that are getting the warning

The "struct queue" inside the typedef refers to an as yet undefined struct.

You need to name your struct, before you can point to it. Fortunately, this is easy to do, like so.

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.

Insert Code Block

assignment from incompatible pointer type

Member Avatar

I have set up the following structs:

and I get the folowings error: assignment from incompatible pointer type I don't understand why both head and node are the same type: Dictionary.

Recommended Answers

change it to this typedef struct DictionaryList* Dictionary; struct DictionaryList { char* word; Line lines; DictionaryList* Next; };

All 2 Replies

Member Avatar

change it to this

The reason is that DictionaryList (defined on line 7) and dictionaryList (used on line 11) are different types.

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.

Insert Code Block

IMAGES

  1. assignment from incompatible pointer type_lby978232的博客-CSDN博客_assignment from

    meaning of assignment from incompatible pointer type

  2. C++, How can I declare a Pointer to a struct in C?

    meaning of assignment from incompatible pointer type

  3. 컴파일 언어와 인터프리터 언어의 차이

    meaning of assignment from incompatible pointer type

  4. c

    meaning of assignment from incompatible pointer type

  5. incompatible pointer types passing int[5][5] to parameter of type int** (C)

    meaning of assignment from incompatible pointer type

  6. c

    meaning of assignment from incompatible pointer type

VIDEO

  1. 4. Pointers

  2. Object Type and Null_pointer_exception Rinku sir 13/10/2022

  3. 17.1 Pointer to a Function

  4. Pointers sample problem no.5

  5. important questions on pointers

  6. MCS011(Problem Solving and Programming)Block-3 Unit-9 (Pointers ) #2

COMMENTS

  1. [SOLVED]: Do not understand: assignment from incompatible pointer type

    main.c:514:15: warning: assignment from incompatible pointer type. sTest in most conexts is regarded as a pointer to the first element of the array and has type "const char*"

  2. c

    Trying to implement signal handlers but receiving the warning:assignment from incompatible pointer type [enabled by default]

  3. [RESOLVED] assignment from incompatible pointer type

    The following lines of code give me a compiler warning "assignment from incompatible pointer type.". That fixed it. For some reason I was thinking it would return a SLIDER* type

  4. c

    Assignment from incompatible pointer type. Maybe someone can help point me in the right direction. unsigned short* x;int textLeft;x = shm->

  5. Assignment from incompatible pointer type (structures, linked list)

    int dictionary_add(dictionary_t *d, const char *key, c. Assignment from incompatible pointer type (structures, linked list) Creating a dictionary data structure using a linked list. typedef struct _dictionary_entry_t { const char* key

  6. How can I solve the warning "assignment from incompatible pointer type"

    void *tratar_alarma(void); {;printf("Alarma activada\n"); };int main(void) {;struct sigaction act; sigset_t mask; int pause(void ); unsigned int alarm(unsigned int seconds)

  7. warning: assignment from incompatible pointer type

    I want to print name and age of person in program Code: #include #include #include typedef struct Per. What's wrong in the code ?

  8. assignment from incompatible pointer type [SOLVED]

    typedef struct{ process *data; struct queue *next; } queue; The "struct queue" inside the typedef refers to an as yet undefined struct. You need to name your struct, before you can point to it. Fortunately

  9. tags-fail

    I have set up the following structs:typedef struct lineList { int lineNum; struct lineList* Next; }*Line; typedef struct DictionaryList { char* word; Line lines; struct dictionaryList* Next; }*Dictionary