1 Zulkinos

C Incompatible Types In Assignment

and are both arrays, and you cannot assign arrays in C (except when the array is embedded in a structure (or union) and you do a structure assignment).

They are also arrays of pointers to char, rather than pointers to arrays of char. What you have written in the code is probably what you want - you could store pointers to up to MAXINT names in the array. However, you should describe the type correctly - as an array of pointers to char or char pointers.

A pointer to an array of characters would look like:

And a point to an array of character pointers (thanks, Brian) would look like:

Be careful of MAXINT; that could be a very large array (on Linux, defines as , which is at least 231-1).


The code looks like:

Neither the assignment to bar nor car should compile at all - is a . You presumably meant to use in some shape or form. As Brian noted, there are problems there, too:

You either want:

Or you want:

Or, indeed:


Finally, dealing with the array assignment, in C you can reasonably use to do this:

The similar function does not have reliable semantics if the areas to be copied overlap, whereas does; it is simpler to always use because it always works correctly. In C++, you need to be cautious about using (or ). In this code, it would be safe enough, but understanding why is non-trivial.

You do need to be aware that you are just copying pointers here - you are not copying the strings that the pointers point at. If something else changes those strings, it affects both the values seen via and the variable in the calling code.

One last point - for now: are you sure you need the argument to the function as a ? It opens up the code to all sorts of abuse which can be prevented if the function is declared to take a '' instead (or even a '').



  1. Join Date
    Apr 2009
    Location
    ~/
    Beans
    210

    C - incompatible types in assignment

    Last edited by ApEkV2; October 16th, 2009 at 12:16 AM.
    Hey there, I just finished this code, and couldn't (didn't know how) fix the two errors: incompatible types in assignment.
    The lines with the error are 97 and 98. And I probably did everything wrong, so any and all help is awesome.

  2. Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,283
    Distro
    Kubuntu

    Re: C - incompatible types in assignment

    Try:
    iph->ip_src.s_addr = inet_addr("127.0.0.1"); iph->ip_dst.s_addr = sin.sin_addr.s_addr;

  3. Join Date
    Apr 2009
    Location
    ~/
    Beans
    210

    Re: C - incompatible types in assignment

    Last edited by ApEkV2; October 15th, 2009 at 11:27 PM.
    That worked. Thanks a lot!
    Now since all the errors are ironed out, when I run it, wireshark picks nothing up, and no traffic.
    I think it's a problem in the tcp/ip headers. Are there any ways to debug this?
    Probably going to make a different thread.

  4. Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,283
    Distro
    Kubuntu

    Re: C - incompatible types in assignment

    What evidence do you have that sendto() was ever called?

    You should start your investigative efforts by examining the value of 'zstop'. It could be that I am losing my eyesight, but no where in the code could I see where you set it to any particular value.

  5. Join Date
    Apr 2009
    Location
    ~/
    Beans
    210

    Re: C - incompatible types in assignment

    Sendto was called, I used strace to make sure.
    here is zstop on line 29
    int h, x, c, s_port, z_key, zstop; char *zvalue = NULL;

  6. Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,283
    Distro
    Kubuntu

    Re: C - incompatible types in assignment

    Wonderful; the sendto() was called by shear luck.

    I see where you defined it; but where did you initialize it to a value less than 3? (hint: nowhere!)
    Originally Posted by ApEkV2
    Sendto was called, I used strace to make sure.
    here is zstop on line 29
    int h, x, c, s_port, z_key, zstop; char *zvalue = NULL;

  7. Join Date
    Apr 2009
    Location
    ~/
    Beans
    210

    Re: C - incompatible types in assignment

    That doesn't change the fact that zstop isn't the problem.

  8. Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,283
    Distro
    Kubuntu

    Re: C - incompatible types in assignment

    Well, I haven't a clue what the problem is because 1) I don't know what parameters you are passing to the application, 2) I don't know if you have the raw socket datagram setup correctly, and 3) whether or not you are using wireshark correctly?

    Nevertheless, it still stands that 'zstop' is an uninitialized value and thus you should fix it.
    Originally Posted by ApEkV2
    That doesn't change the fact that zstop isn't the problem.

  9. Join Date
    Apr 2009
    Location
    ~/
    Beans
    210

    Re: C - incompatible types in assignment

    Last edited by ApEkV2; October 16th, 2009 at 12:13 AM.
    I fixed zstop before my last post, and I'm only using 192.168.1.100 80 as arguments.
    I believe I've already said where I think the problem is (in the tcp/ip headers).

  10. Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,283
    Distro
    Kubuntu

    Re: C - incompatible types in assignment

    When you used strace, what was the return value from the call to sendto()?

Leave a Comment

(0 Comments)

Your email address will not be published. Required fields are marked *