Why do I get these warnings?

The compiler showed the following warnings for the following code segment. Please help me correct it.

if((tmp_n = (struct dot *)shmat(shm_net, NULL, 0)) == (int *) -1) { } warning: comparison of distinct pointer types lacks a cast [enabled by default]

Its a C program, this code segment is for attaching a shared memory segment to a pointer **tmp_n which is of the type struct dot.

struct dot {int weight; int tmv;};

Answers


Try this one

if((tmp_n = (struct dot *)shmat(shm_net, NULL, 0)) == (void *) -1) { }

and look at the man-page, it states:

Return Value
On success shmat() returns the address of the attached shared memory segment; 
on error (void *) -1 is returned, and errno is set to indicate the cause of the error. 

You need to cast -1 to the same pointer type as the variable you're comparing with:

if((tmp_n = (struct dot *)shmat(shm_net, NULL, 0)) == (struct dot *) -1) { }

Need Your Help

Redirecting https requests to two different weblogic servers using the Weblogic proxy and Apache2

apache2 weblogic solaris reverse-proxy

I have a server serverA running a weblogic application App1, with base url /app1/ on port 7001, and another server serverB, running a weblogic application App2, with base url /app2/ on port 8001. B...

Change labels of custom post type via child theme

wordpress wordpress-theming custom-post-type

I have a parent wordpress theme that uses a custom post type of "portfolio" but I want to change this to "property." I'd like to have all of the contextual elements changed to show "property" like,...