Thread: Pointer type check warning

  1. #1
    Registered User kw42chan's Avatar
    Join Date
    Jan 2013
    Location
    Hong Kong, China
    Posts
    18

    Pointer type check warning

    Hi,
    I have some questions about type check warning. I am reading the tutorial notes from http://www.clear.rice.edu/comp221/ht...s-pointers.pdf

    CASE 1

    Code:
    int int1 = 1036; /* some data to point to */
    int int2 = 8;
    int *int_ptr1 = &int1; /* get addresses of data */
    int *int_ptr2 = &int2;
    *int_ptr1 = int_ptr2;
    *int_ptr1 = int2;

    it said "Type check warning: int_ptr2 is not an int"and "int1 becomes 8"

    CASE 2

    Code:
    int int1 = 1036; /* some data to point to */int int2 = 8;
    int *int_ptr1 = &int1; /* get addresses of data */
    int *int_ptr2 = &int2;
    int_ptr1 = *int_ptr2;
    int_ptr1 = int_ptr2;


    it said "Type check warning: *int_ptr2 is not an int *" and "Changes int_ptr1 – doesn’t change int1"
    Can anyone explain?


  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Look carefully:
    Code:
    *int_ptr1 = int_ptr2;
    int_ptr1 is a pointer to int, hence *int_ptr1 is an int. Thus, it does not make sense to assign int_ptr2 to *int_ptr1 since you would be assigning a pointer to an int.
    Quote 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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Warning: incompatible pointer type
    By Cnewbi in forum C Programming
    Replies: 7
    Last Post: 12-29-2011, 03:17 PM
  2. How would I fix this incompatible pointer type warning
    By ogglock in forum C Programming
    Replies: 2
    Last Post: 07-11-2011, 01:17 AM
  3. [Warning] Incompatible pointer type
    By dgs012 in forum C Programming
    Replies: 5
    Last Post: 02-20-2011, 11:27 AM
  4. Incompatible Pointer Type Warning
    By kwikness in forum C Programming
    Replies: 5
    Last Post: 10-30-2007, 06:14 PM

Tags for this Thread