warning: assignment makes integer from pointer without a cast

  • I'm getting the following warning and I can't figure out how to
    suppress it, or whether or not I really need to worry about it.

    warning: assignment makes integer from pointer without a cast

    The warning is on the following line of code which calls a *private*
    method (meaning that I haven't declared a prototype in the .h file and
    don't want to).  I imagine the compiler thinks the method will return
    an id and this is why I'm getting the error, but do I need to worry
    about this?  I tried creating a category in the same .m file and
    declaring the prototype there, but I still get the warning.  Declaring
    the prototype in the .h file *does* make the warning disappear, but
    I'd rather not declare it there because I don't want consumers of the
    interface to call it.

    BOOL myBoolean = [self methodThatReturnsABool];

    Any suggestions for how to correctly deal with this situation but
    still leave the method private?  I read online about a similar problem
    when calling a delegate method and expecting a return of type BOOL,
    but I'm not sure that solution applies here.

    Thanks!

    -Ryan
  • I would have thought that making a category would have fixed it.
    Maybe double-check and verify that the category solution isn't working?

    On Oct 16, 2007, at 9:36 AM, Ryan Poling wrote:

    > I'm getting the following warning and I can't figure out how to
    > suppress it, or whether or not I really need to worry about it.
    >
    > warning: assignment makes integer from pointer without a cast
    >
    > The warning is on the following line of code which calls a
    > *private* method (meaning that I haven't declared a prototype in
    > the .h file and don't want to).  I imagine the compiler thinks the
    > method will return an id and this is why I'm getting the error, but
    > do I need to worry about this?  I tried creating a category in the
    > same .m file and declaring the prototype there, but I still get the
    > warning.  Declaring the prototype in the .h file *does* make the
    > warning disappear, but I'd rather not declare it there because I
    > don't want consumers of the interface to call it.
    >
    > BOOL myBoolean = [self methodThatReturnsABool];
    >
    > Any suggestions for how to correctly deal with this situation but
    > still leave the method private?  I read online about a similar
    > problem when calling a delegate method and expecting a return of
    > type BOOL, but I'm not sure that solution applies here.
    >
    > Thanks!
    >
    > -Ryan
  • Ryan,

    The problem is that the compiler hasn't encountered a declaration of -
    methodThatReturnsABool, so it assumes the return type is id.  You can
    avoid the compiler warning by declaring a category (as John Stiles
    had suggested) local to the file in which you use the method...

    @interface MyClass(Private)
    - (BOOL) methodThatReturnsBool;
    @end

    dave

    On 16-Oct-07, at 10:36 AM, Ryan Poling wrote:

    > I'm getting the following warning and I can't figure out how to
    > suppress it, or whether or not I really need to worry about it.
    >
    > warning: assignment makes integer from pointer without a cast
    >
    > The warning is on the following line of code which calls a
    > *private* method (meaning that I haven't declared a prototype in
    > the .h file and don't want to).  I imagine the compiler thinks the
    > method will return an id and this is why I'm getting the error, but
    > do I need to worry about this?  I tried creating a category in the
    > same .m file and declaring the prototype there, but I still get the
    > warning.  Declaring the prototype in the .h file *does* make the
    > warning disappear, but I'd rather not declare it there because I
    > don't want consumers of the interface to call it.
    >
    > BOOL myBoolean = [self methodThatReturnsABool];
    >
    > Any suggestions for how to correctly deal with this situation but
    > still leave the method private?  I read online about a similar
    > problem when calling a delegate method and expecting a return of
    > type BOOL, but I'm not sure that solution applies here.
    >
    > Thanks!
    >
    > -Ryan
  • Put the prototype in a "private" declaration, at the top of the class
    file, like:

    @interface YourClass (PRIVATE)
    -(BOOL) methodThatReturnsABool;
    @end

    That will fix your compile errors without exposing the method outside
    the class

    On Oct 16, 2007, at 12:36 PM, Ryan Poling wrote:

    > I'm getting the following warning and I can't figure out how to
    > suppress it, or whether or not I really need to worry about it.
    >
    > warning: assignment makes integer from pointer without a cast
    >
    > The warning is on the following line of code which calls a *private*
    > method (meaning that I haven't declared a prototype in the .h file
    > and don't want to).  I imagine the compiler thinks the method will
    > return an id and this is why I'm getting the error, but do I need to
    > worry about this?  I tried creating a category in the same .m file
    > and declaring the prototype there, but I still get the warning.
    > Declaring the prototype in the .h file *does* make the warning
    > disappear, but I'd rather not declare it there because I don't want
    > consumers of the interface to call it.
    >
    > BOOL myBoolean = [self methodThatReturnsABool];
    >
    > Any suggestions for how to correctly deal with this situation but
    > still leave the method private?  I read online about a similar
    > problem when calling a delegate method and expecting a return of
    > type BOOL, but I'm not sure that solution applies here.
    >
    > Thanks!
    >
    > -Ryan
  • On 16 Oct 2007, at 17:36, Ryan Poling wrote:

    > I'm getting the following warning and I can't figure out how to
    > suppress it, or whether or not I really need to worry about it.
    >
    > warning: assignment makes integer from pointer without a cast
    >
    > The warning is on the following line of code which calls a
    > *private* method (meaning that I haven't declared a prototype in
    > the .h file and don't want to).  I imagine the compiler thinks the
    > method will return an id and this is why I'm getting the error, but
    > do I need to worry about this?  I tried creating a category in the
    > same .m file and declaring the prototype there, but I still get the
    > warning.  Declaring the prototype in the .h file *does* make the
    > warning disappear, but I'd rather not declare it there because I
    > don't want consumers of the interface to call it.

    So declare the prototype in the .m file. If you don't want to do that
    you'd probably get away with simply putting the definition _above any
    code that calls it_ inside your class[0]. The compiler is complaining
    because at the time it is called it haven't seen a prototype for it
    and therefore assumes that the method  will return 'id'.

    [0] this will work _almost_ anywhere, except for recursive methods.

    Stig

    --
    http://code.brautaset.org
    http://blog.brautaset.org
  • Thanks everyone for the replies.  I had tried using a category before
    posting the original message, but I had placed the @interface portion
    of the category declaration *below* the @implementation of the regular
    class, so as you mentioned, the compiler didn't see it in time.
    Simply moving the @interface portion of the category to the top of
    the .m file fixed the warning.  Oops.  Simple problem!

    -Ryan

    On Oct 16, 2007, at 10:05 AM, David Spooner wrote:

    > Ryan,
    >
    > The problem is that the compiler hasn't encountered a declaration of
    > -methodThatReturnsABool, so it assumes the return type is id.  You
    > can avoid the compiler warning by declaring a category (as John
    > Stiles had suggested) local to the file in which you use the method...
    >
    > @interface MyClass(Private)
    > - (BOOL) methodThatReturnsBool;
    > @end
    >
    > dave
    >
    > On 16-Oct-07, at 10:36 AM, Ryan Poling wrote:
    >
    >> I'm getting the following warning and I can't figure out how to
    >> suppress it, or whether or not I really need to worry about it.
    >>
    >> warning: assignment makes integer from pointer without a cast
    >>
    >> The warning is on the following line of code which calls a
    >> *private* method (meaning that I haven't declared a prototype in
    >> the .h file and don't want to).  I imagine the compiler thinks the
    >> method will return an id and this is why I'm getting the error, but
    >> do I need to worry about this?  I tried creating a category in the
    >> same .m file and declaring the prototype there, but I still get the
    >> warning.  Declaring the prototype in the .h file *does* make the
    >> warning disappear, but I'd rather not declare it there because I
    >> don't want consumers of the interface to call it.
    >>
    >> BOOL myBoolean = [self methodThatReturnsABool];
    >>
    >> Any suggestions for how to correctly deal with this situation but
    >> still leave the method private?  I read online about a similar
    >> problem when calling a delegate method and expecting a return of
    >> type BOOL, but I'm not sure that solution applies here.
    >>
    >> Thanks!
    >>
    >> -Ryan
    >
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today