C prototype definition question

Started by hutch--, January 26, 2005, 02:59:50 AM

Previous topic - Next topic

hutch--

I confess to being out of date with my C data types but I have a problem converting a C prototype for an OpenGL prototype that I don't know how to convert.

Its is related to the definition of "void" as a data type.

I understand it in terms of a return value,


    void funcname(args);


I also understand it as a function argument to indicate there are no parameters to the function,


    funcname(void);


Where I am in trouble is with a prototype that has a multiple argument list that has "void" as an argument.

The examples are from the OpenGL header file GL.H .


typedef void GLvoid;   // typedef


Prototypes


WINGDIAPI void APIENTRY glCallLists (GLsizei n, GLenum type, const GLvoid *lists);
WINGDIAPI void APIENTRY glColorPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
WINGDIAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);


Any assistance here would be appreciated as I have the rest of the prototypes and equates converted with no problems
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Relvinian

#1
Hutch,

Here's some C prototypes and their corresponding ASM prototypes in order to help you understand what they are:

C
==
void MyFunc();
void MyFunc1(void);
void MyFunc2(void* ptr);
void* MyFunc3(const void* ptr);

ASM
=====
MyFunc proto
MyFunc endp

MyFunc1 proto
MyFunc1 endp

MyFunc2 proto ptr:dword   ; a pointer to an object as a parameter.
MyFunc2 endp

MyFunc3 proto ptr:dword   ; a pointer to an object as a parameter
   mov eax, [retPtr]
MyFunc3 endp


Basically, prototypes in C/C++ with a void* is the same as a DWORD in 32-bit and a QWORD in 64-bt.  void* are also known as a common way to type cast something like a char* to a function or a object pointer to a function when the function doesn't care what type of pointer is it. Like when you see the prototype for memcpy, it looks like this:

void* memcpy(void* dest, const void* src, size_t count);


This is returning a pointer to the object, takes two pointers and a size (length) to copy.  For example:
MyString1  db 255 dup (?)
MyString2  db 256 dup (?)

invoke memcpy, addr MyString2, addr MyString1, 255


If a '*' doesn't appear after the void, then the function doesn't return or take any arguments.  You MUST have a '*' after the void to have a meaningful parameter.

So in the typedef you see:

typedef void GLvoid;


You'll notice that most places where GLvoid is used also has a * after it to mean a pointer to some type of object (whether it is a value or object).

Hope this helps

Relvinian

hutch--

#2
Thanks,

It looks like in this context that the parameters are pointer types and thus in assembler are properly DWORD in size.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Relvinian

Hutch,

Yep, in the code you provided, all the GLvoid* (GLvoid *) are prototyped as DWORD parameters.

Relvinian

MichaelW

From the PSDK for the glCallLists function:
Quote
lists
The address of an array of name offsets in the display list. The pointer type is void because the offsets can be bytes, shorts, ints, or floats, depending on the value of type.
eschew obfuscation