return makes pointer from intger without a cast

4 posts / 0 new
Last post
JosDuchIt
JosDuchIt's picture
Offline
Last seen: 7 years 4 months ago
Joined: 2012-01-08 20:57
return makes pointer from intger without a cast

I get the mentioned warning for the return below

  1. void* findpath(const char *filename)
  2. {
  3.  
  4. if (IoErr() == ERROR_OBJECT_IN_USE)
  5. return -1;
  6.  
  7.  
  8.  
  9. }

The function is used as this

#define ZERO ((BPTR)NULL)
BPTR gcprog=ZERO;
if ((gcprog = findpath("Gui4Cli")) != ((BPTR)-1))

I get the same warning though with with
return (BPTR)-1;

How can i get rid of it?

thomas
thomas's picture
Offline
Last seen: 2 hours 32 min ago
Joined: 2011-05-16 14:23
If you declare your function

If you declare your function as returning a void* you need to cast to void*. If you want to cast to BPTR, you should declare your function as returning a BPTR. Generally you should declare your function as true as possible. So if you return a BPTR, declare it as BPTR.

either

void* findpath()
{
return (void*) -1;
}

or

BPTR findpath()
{
return (BPTR) -1;
}

corto
corto's picture
Offline
Last seen: 7 years 1 month ago
Joined: 2011-09-09 11:43
JoshDuchIt: What findpath is

JoshDuchIt: What findpath is supposed to return ? A string ? If so, what about returning NULL and declaring the format of the return value as "char *" ?
But maybe you want to distinguish the error case ERROR_OBJECT_IN_USE and others.

JosDuchIt
JosDuchIt's picture
Offline
Last seen: 7 years 4 months ago
Joined: 2012-01-08 20:57
@thomas, thanks @corto What

@thomas, thanks
@corto

What findpath is supposed to return ?

As shown in the usage of the function:
BPTR gcprog=ZERO;
and
if ((gcprog = findpath("Gui4Cli")) != ((BPTR)-1))
findpath would be OK if it returned a BPTR

I took over the suggestion of Thomas, and the stuff compiles OK now
Thanks too

Log in or register to post comments