stdlib.h in cocoa.h?

Discussion in 'Mac Programming' started by ArtOfWarfare, Nov 26, 2008.

  1. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #1
    I'm slowly working my way through this book Introduction to OpenGL (perhaps too slowly... I think my understanding of C / Objective-C / Objective-C 2.0 / Cocoa / Cocoa Touch are all slipping away as I read this... hopefully looking over my previous projects will bring back the memories of how it all works...) and I noticed that one of the examples in it has:

    Code:
    #include <GL/gl.h>
    #include <GL/glu.h>
    #include <GL/glut.h>
    #include <stdlib.h>
    I changed it to:

    Code:
    #import <Cocoa/Cocoa.h>
    #import <OpenGL/gl.h>
    #import <OpenGL/glu.h>
    #import <GLUT/glut.h>
    I ran it and it works fine... but it made me wonder about stdlib.h. Is it already included in cocoa.h? Or is it just that the example in the book didn't need stdlib.h to work properly and that in the future I may need to include it? (Where would I find the framework that includes it anyways?)
     
  2. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #2
    If you include the glut.h header file there is no need to include gl.h and glu.h as well. In fact it is specifically stated by the standards body not too as glut.h includes them itself in the correct order to satisfy certain platform issues.

    In answer to your question cocoa.h does include it in a round about way.

    Cocoa.h includes AppKit.h which in turn includes Foundation.h which includes CoreFoundation.h and then finally that includes stdlib.h. Of course you could have just looked in the header files yourself to see that :).
     
  3. ArtOfWarfare thread starter macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #3
    I looked in the header files of Cocoa only... it didn't occur to me that it would be buried so many layers deep. But it confirms what I already suspected.

    Oh?

    Odd that the examples in the book include all 3 then. Well, I changed it to only import glut.h now (and it still works.)
     

Share This Page