What's the advantage of using GLuint instead of unsigned int?

前端 未结 4 1823
说谎
说谎 2021-01-03 18:15

I like to be more standard as possible, so why should I \"constrain\" my classes defining it\'s members as OpenGL types when I can use primitive types? Is there any advantag

4条回答
  •  温柔的废话
    2021-01-03 18:43

    The advantages has already been mentioned here. However, there is a disadvantage clear from the following examples:

    class FileIn
        {
        public:
            //Public interface like read
        private:
            void* handle;
        };
    

    The above code fits very well in a platform independent header but writing

    #define WIN32_LEAN_AND_MEAN
    #include 
    
    class FileIn
        {
        public:
            //Public interface like read
        private:
            HANDLE handle;
        };
    

    does not.

    Though the former will require ugly typecasts like

    int fd=(int)( (size_t)handle );
    close(fd);
    

    i do not know any system which have sizeof(void*) < sizeof(int). Yes it will fail if open returns a negative number for a valid file handle.

    What to learn about this? Avoid using typedefs in library include files. Instead use struct declarations even though C programmers need to write struct a dozen times. Here, some C standard library implementations do it all wrong.

    Right

    In stdio.h:

    struct FILE;
    

    And in the application:

    struct FILE* the_file=fopen("filename.txt","rb");
    /*...*/
    

    Wrong

    In stdio.h:

    typedef struct SOMENAMETHATNOONESHOULDUSE
        {
        /* Internal data members */
        } FILE;
    

    In application

    FILE* the_file=fopen("filename.txt","rb");
    

    When writing a C++ wrapper, this forces either #include or simply declare the handle as above.

提交回复
热议问题