function declaration and definition

D

dmjcunha

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.
 
J

James Kuyper

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.
 
B

Barry Schwarz

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top