Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > function declaration and definition

Reply
Thread Tools

function declaration and definition

 
 
dmjcunha@gmail.com
Guest
Posts: n/a
 
      09-19-2012
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.
 
Reply With Quote
 
 
 
 
James Kuyper
Guest
Posts: n/a
 
      09-19-2012
On 09/19/2012 02:38 PM, http://www.velocityreviews.com/forums/(E-Mail Removed) 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.

 
Reply With Quote
 
 
 
 
Barry Schwarz
Guest
Posts: n/a
 
      09-19-2012
On Wed, 19 Sep 2012 11:38:30 -0700 (PDT), (E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Include files with function prototypes and variable declaration/definition Kristian Virkus C Programming 7 02-08-2007 07:22 AM
Can a static function declaration conflict with a non-static declaration? nospam_timur@tabi.org C Programming 4 12-12-2006 10:26 PM
Variable declaration taken as a function pointer declaration Bolin C++ 4 12-02-2005 05:28 PM
"unable to match function definition to an existing declaration" Maett C++ 5 09-11-2005 07:09 PM
Function declaration in class declaration Ovidesvideo C++ 4 12-10-2004 06:36 PM



Advertisments