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

Use My Existing Forum Account
- Stack Overflow Public questions & answers
- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Talent Build your employer brand
- Advertising Reach developers & technologists worldwide
- About the company
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?
- 2 What is shm? How is it defined? if it is int textLeft[16] , then it's normal, unsigned short* is NOT the same as signed int[] – Eregrith Dec 19, 2013 at 11:04
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
- cast the pointer, x = (unsigned short *)(shm->textLeft); , and
- compile with GCC's -fno-strict-aliasing to turn the aliasing rule off.
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.
- +1 In C, type errors doesn't really exist, it's just that you haven't cast things enough. </irony> – user1019830 Dec 19, 2013 at 11:17
- 1 @HermanTorjussen: type errors do exist; without the -fno-strict-aliasing (a GCC-specific option), the compiler is free to break this code in any way it pleases. – Fred Foo Dec 19, 2013 at 11:19
- And that was my attempt at humour.. My point was that C is not very strict with types. – user1019830 Dec 19, 2013 at 11:20
- 1 @larsmans: You should have added: " Don't try this at home! " ...;-) – alk Dec 19, 2013 at 11:21
- 2 @HermanTorjussen: apologies, irony doesn't always pass through the internet unscathed. – Fred Foo Dec 19, 2013 at 11:21
- x as int * or
- textLeft[16] as unsigned short
and things are ok.

- You're right, I thought I had did that before but it took care of the error. But I remember now I get another error from something else. I get an "Invalid Argument" when before doing int it didn't have that. – user2318083 Dec 19, 2013 at 11:15
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.
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 .
- The Overflow Blog
- Five Stack Exchange sites turned ten years old this quarter!
- “Move fast and break things” doesn’t apply to other people’s savings (Ep. 544)
- Featured on Meta
- We've added a "Necessary cookies only" option to the cookie consent popup
- Launching the CI/CD and R Collectives and community editing features for...
- The [amazon] tag is being burninated
- Temporary policy: ChatGPT is banned
- Staging Ground Beta 1 Recap, and Reviewers needed for Beta 2
Hot Network Questions
- C++ Minimal CSV parser cut2
- Properties of categorical zeta function
- What equation tells you how far in space you can go from a point and return?
- Concrete base for parcel box
- Each Element of Obarray is A Bucket?
- Can there be a repulsion between an electron beam and a proton beam depending on the beam's velocities?
- What is the name of the color used by the SBB (Swiss Federal Railway) in the 1920s to paint their locomotive?
- Max-heap implementation in C
- Does every US state set its standard deduction to match the federal one? Why?
- Why is the work done by the tension in a pendulum string 0?
- Was the NATO bombing of Yugoslavia an "invasion" or not?
- C++ Is Taking a reference from a temporary valid code?
- Calculate the angle of Escape
- Gas furnace takes like 2-5 minutes from ignition to blower start. flame also burning yellow/orange
- How do/should administrators estimate the cost of producing an online introductory mathematics class?
- Forced to pay a customs fee for importing a used wedding dress into the Netherlands. Is there a way to avoid paying?
- server trace question
- Can Quantum Computers crack RSA and AES?
- Chimeric Animals from Icewind Dale
- In England, why are some high schools called hospitals?
- Why do I get two different answers while doing this simple limit math?
- SQL sanitizing in code with no user input
- Are there any medieval manuals relating to castle building?
- One-day-ahead prediction of S&P500 with Temporal Convolutional Networks
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.

- Today's Posts
- C and C++ FAQ
- Mark Forums Read
- View Forum Leaders
- What's New?
- Get Started with C or C++
- C++ Tutorial
- Get the C++ Book
- All Tutorials
- Advanced Search

- General Programming Boards
- C Programming

warning: assignment from incompatible pointer type
- Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems
Thread: warning: assignment from incompatible pointer type
Thread tools.
- Show Printable Version
- Email this Page…
- Subscribe to this Thread…
Search Thread
- Advanced Search
- Linear Mode
- Switch to Hybrid Mode
- Switch to Threaded Mode
- View Profile
- View Forum Posts

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 ?
- Visit Homepage

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.
- Private Messages
- Subscriptions
- Who's Online
- Search Forums
- Forums Home
- C++ Programming
- C# Programming
- Game Programming
- Networking/Device Communication
- Programming Book and Product Reviews
- Windows Programming
- Linux Programming
- General AI Programming
- Article Discussions
- General Discussions
- A Brief History of Cprogramming.com
- Contests Board
- Projects and Job Recruitment

- How to create a shared library on Linux with GCC - December 30, 2011
- Enum classes and nullptr in C++11 - November 27, 2011
- Learn about The Hash Table - November 20, 2011
- Rvalue References and Move Semantics in C++11 - November 13, 2011
- C and C++ for Java Programmers - November 5, 2011
- A Gentle Introduction to C++ IO Streams - October 10, 2011
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
- C and C++ Programming at Cprogramming.com
- Web Hosting
- Privacy Statement
assignment from incompatible pointer type

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
- 2 Contributors
- 6 Hours Discussion Span
- Latest Post 14 Years Ago Latest Post by Salem
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

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.
- 3 Contributors
- 15 Hours Discussion Span
- Latest Post 11 Years Ago Latest Post by arkoenig
Recommended Answers
change it to this typedef struct DictionaryList* Dictionary; struct DictionaryList { char* word; Line lines; DictionaryList* Next; };
All 2 Replies

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
VIDEO
COMMENTS
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*"
Trying to implement signal handlers but receiving the warning:assignment from incompatible pointer type [enabled by default]
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
Assignment from incompatible pointer type. Maybe someone can help point me in the right direction. unsigned short* x;int textLeft;x = shm->
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
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)
I want to print name and age of person in program Code: #include #include #include typedef struct Per. What's wrong in the code ?
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
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