function declaration and definition

Discussion in 'C Programming' started by dmjcunha@gmail.com, Sep 19, 2012.

  1. Guest

    I am studying mesa3d source files and I found lots of function declarations and definitions not seen in the book The C programming language.
    For example, in the file gl.h I found:

    GLAPI void GLAPIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha );

    What is the GLAPI and GLAPIENTRY?

    Then in the file clear.c I found:

    void GLAPIENTRY
    _mesa_ClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
    {
    GLfloat tmp[4];
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);

    tmp[0] = red;
    ...

    Again what is the GLAPIENTRY?

    Is _mesa_ClearColor(...
    after compilation transformed in the glClearColor(... seen in the header file?

    If someone can explain me in general terms I would thank, although if someone knows specifically about mesa3d it is better.
    Thanks in advance.
    , Sep 19, 2012
    #1
    1. Advertising

  2. James Kuyper Guest

    On 09/19/2012 02:38 PM, wrote:
    > I am studying mesa3d source files and I found lots of function declarations and definitions not seen in the book The C programming language.
    > For example, in the file gl.h I found:
    >
    > GLAPI void GLAPIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha );
    >
    > What is the GLAPI and GLAPIENTRY?


    The C language lets you give identifiers definitions that you can use
    later on. By convention, identifiers that are all UPPER CASE are usually
    macros created by #define preprocessing statements. If those conventions
    are being ignored, they could also be typedefs. Whether macros or
    typedefs or one of each, they should be defined somewhere before the
    first time they are used, either in gl.h, or in some other file
    #included within gl.h prior to the point of first use.

    You could find out how those identifiers are defined by tracking it down
    in the header files. However, it would probably be more productive to
    look them up in the documentation of mesa3d (if you have access to that
    documentation).

    > Then in the file clear.c I found:
    >
    > void GLAPIENTRY
    > _mesa_ClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
    > {
    > GLfloat tmp[4];
    > GET_CURRENT_CONTEXT(ctx);
    > ASSERT_OUTSIDE_BEGIN_END(ctx);
    >
    > tmp[0] = red;
    > ...


    Identifiers starting with an '_' followed by a lower case letter are
    reserved at file scope for use by the C implementation. Function
    definitions like that above can only appear at file scope, so the
    behavior of any program of which clear.c is a part is undefined. The
    fact that the authors of clear.c were not aware of that fact (or didn't
    care) is a bad sign. Be careful when using this package.

    > Again what is the GLAPIENTRY?
    >
    > Is _mesa_ClearColor(...
    > after compilation transformed in the glClearColor(... seen in the header file?


    That's not likely; but _mesa_ClearColor could be a macro defined as
    expanding to glClearColor (or vice versa). However, whether or not
    that's the case is not clear from the code you've provided.

    > If someone can explain me in general terms I would thank, although if someone knows specifically about mesa3d it is better.


    Questions about mesa3d, rather than C, are better posed in a forum
    specific to mesa3d. Your questions are only nominally about C, they're
    primarily about mesa3d, so I would recommend finding such a forum.
    <http://www.mesa3d.org/> would seem the appropriate place - try the
    mailing list.
    James Kuyper, Sep 19, 2012
    #2
    1. Advertising

  3. On Wed, 19 Sep 2012 11:38:30 -0700 (PDT), wrote:

    >I am studying mesa3d source files and I found lots of function declarations and definitions not seen in the book The C programming language.
    >For example, in the file gl.h I found:
    >
    >GLAPI void GLAPIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha );
    >
    >What is the GLAPI and GLAPIENTRY?
    >
    >Then in the file clear.c I found:
    >
    >void GLAPIENTRY
    >_mesa_ClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
    >{
    > GLfloat tmp[4];
    > GET_CURRENT_CONTEXT(ctx);
    > ASSERT_OUTSIDE_BEGIN_END(ctx);
    >
    > tmp[0] = red;
    > ...
    >
    >Again what is the GLAPIENTRY?
    >
    >Is _mesa_ClearColor(...
    >after compilation transformed in the glClearColor(... seen in the header file?
    >
    >If someone can explain me in general terms I would thank, although if someone knows specifically about mesa3d it is better.
    >Thanks in advance.


    Most likely, they are macros (that are usually defined in a different
    header).

    Macros like GLAPIENTRY usually contain some system specific extension
    that provides the compiler information about calling conventions.
    GLAPI might be defined as static, extern, or inline depending on the
    stage of development as the product went through testing.

    On the other hand, they might be anything else the developer decided.

    --
    Remove del for email
    Barry Schwarz, Sep 19, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ovidesvideo
    Replies:
    4
    Views:
    506
    Andrey Tarasevich
    Dec 10, 2004
  2. Replies:
    4
    Views:
    1,075
    Richard Tobin
    Dec 12, 2006
  3. Kristian Virkus
    Replies:
    7
    Views:
    405
    Thad Smith
    Feb 8, 2007
  4. Maett
    Replies:
    5
    Views:
    2,102
    Maett
    Sep 11, 2005
  5. Bolin
    Replies:
    4
    Views:
    408
Loading...

Share This Page