Re: shmat() return values?



On Mon, May 26, 2008 at 08:14:38PM +0300, Krassimir Slavchev wrote:
Hello,

When I try:

if ((*shm = shmat(shmid, NULL, 0)) == -1)

The gcc complains with:
warning: comparison between pointer and integer

shmat() is declared in shm.h as:
void *shmat(int, const void *, int);

but 'man 4 shmat;

RETURN VALUES
Upon success, shmat() returns the address where the segment is
attached;
otherwise, -1 is returned and errno is set to indicate the error.


What is the correct return value on failure, -1 or NULL?
I think it should be NULL?

The return value is a void pointer, with value equivalent to -1,
so (void *)-1

So you can replace it with:

if ((*shm = shmat(shmid, NULL, 0)) == (void*)-1)

Marc
_______________________________________________
freebsd-stable@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: confusion: casting function pointers
    ... pointer from the 'actual/other modules' that takes arguments of type ... list to types of void *). ... int main{ ... without a prototype, a number of special "promotion" rules take ...
    (comp.lang.c)
  • Re: invalid pointer adress
    ... >> pointer causes the program to exit with a core dump. ... struct s2{void *p;}; ... int leseExterneHinweise_masch_storno ... typedef struct s_AusdatFeldbeschreibung ...
    (comp.lang.c)
  • Should io(read|write)(8|16|32)_rep take (const|) volatile u(8|16|32) __iomem *addr?
    ... the destination pointer on user-space ... @src: ... const void *data, int bytelen); ...
    (Linux-Kernel)
  • Re: function pointer help!
    ... //the return void and input prameters are defined in the manual... ... void MyProjectView::CallHandler(int,unsigned int, unsigned int, void*) ... You are attempting to use a C++ member function as the callback, but the callback is defined in terms or C, not C++. ... The underlying problem is that C++ functions receive a hidden parameter, the 'this' pointer, so their signature is incompatible with C definitions. ...
    (microsoft.public.vc.mfc)
  • Re: Whats the meaning of this code
    ... void * work ... Whats the meaning of this line:- ... The meaning...a function called work that accepts a pointer of type ... pointer value is cast to an int value. ...
    (comp.lang.c)