[GDCC - SOLVED]Need Pointers on Pointers

Discuss anything ZDoom-related that doesn't fall into one of the other categories.
Post Reply
User avatar
Sarah
Posts: 551
Joined: Wed Sep 06, 2006 12:36 pm
Preferred Pronouns: She/Her
Operating System Version (Optional): Debian 11 (bullseye), Windows 10
Location: Middle of Nowheresville Il.
Contact:

[GDCC - SOLVED]Need Pointers on Pointers

Post by Sarah »

Yeah, bad pun :3:

I'm realizing after the fact that Visual Studio has a tendency to be a personal royal pain in the, well you know where; even after enforcing strict ANSI the code worked just fine in VS but I'm having an odd problem with GDCC concerning pointers.

Code: Select all

//
// This prototype specifies a double pointer (pointer to pointer) as an argument
//
void zSys_nINST_ExtHandler (nWND *, bool, bool *, bool, unsigned short, bool, nWND **, bool, unsigned short, MSGS);
A couple notes on aruments:
  1. nWND - structure, often sent to functions via pointer
  2. MSGS - enum (ie, message), usually controls function switch/case blocks

Code: Select all

//
// This snippet shows a typical call to the function
//
nWND * zGibZone_Detect (void)
{
	bool hChk = false;
	int mse_x, mse_y,
		enwd_glx, enwd_gly, enwd_grx, enwd_gry;
	unsigned short nwdCnt = ZERO;
	nWND *enwd = NULL,
		*rnwd = NULL;

	zSys_nINST_ExtHandler(NULL_NWNDp, true, &hChk, false, ZERO, false, &NULL_NWNDp, true, &nwdCnt, MSG_NULL);
	
	if(hChk == true && nwdCnt > ZERO)
	{
		for(int i = nwdCnt -= ONE; i > ZERO; i--)
		{
			zSys_nINST_ExtHandler(NULL_NWNDp, true, &hChk, false, i, true, &enwd, false, NULL_LWORDSp, MSG_GET);
			if(hChk == true)
			{
             . . . further function beyond . . .
Another note:
  1. NULL_NWNDp is a pointer of type nWND (structure pointer) which should point to NULL_NWND, a structure of the same type.
So, the what on earth is going on here
While the function doesn't actually have a return that is meaningful, the arguments give the function access to a group of important variables and options that can be modified;
the function allows for the storage and retrieval of the address of a structure, which is useful in instances where a function is not given a structure to work with as one of it's
arguments (ie, the snippet). In the case where the function is used to retrieve a structure address the double pointer argument is the pointer to the pointer that should be set
to the address of the structure (yes quite roundabout).

In question is the argument sporting the flashy double pointer (pointer to pointer); while this worked fine in Visual Studio, as shown in the snippet, this does not seem to impress
GDCC. I receive the following error, which is quite confuzzling:
GDCC wrote:ERROR: src/zgibz.c:50:24: cannot implicitly convert to arithmetic type from non-arithmetic type
make: *** [bin/zgibz.ir] Error 1
Of course that's the first call to the function. Initially this was a different error because I was not sending the pointer address to the double pointer. While this snippet is based
on the original code built in Visual Studio, I did comment my way down to the code from Visual Studio which has similar calls and produced the same error. So I'm left quite stumped
as to what is actually wrong here and just how to fix it. Any insight is deeply appreciated, I wasn't expecting this function to be a problem.
Last edited by Sarah on Fri Feb 12, 2016 12:30 am, edited 1 time in total.
User avatar
DavidPH
Posts: 382
Joined: Fri Aug 28, 2009 1:46 pm

Re: [GDCC]Need Pointers on Pointers

Post by DavidPH »

That error message has nothing to do with pointers-to-pointers, except possibly a missing dereference. It means exactly what it says: You have attempted to implicitly convert a non-arithmetic type (probably a pointer type, since VS allows it) to an arithmetic type. Which is a constraint violation in C, even if compilers usually allow it.

Anyway. Assuming the first call to zSys_nINST_ExtHandler is the line generating the error, the problem would seem to be converting &nwdCnt to unsigned short for the second to last argument.
User avatar
Sarah
Posts: 551
Joined: Wed Sep 06, 2006 12:36 pm
Preferred Pronouns: She/Her
Operating System Version (Optional): Debian 11 (bullseye), Windows 10
Location: Middle of Nowheresville Il.
Contact:

Re: [GDCC]Need Pointers on Pointers

Post by Sarah »

Yep you're absolutely right; that second to last argument should be a pointer, and it is not. I must have manually written the prototype instead of copying it from VS. The reason I thought it was the double pointer was that I originally had an error involving it (forgot to send the pointer via reference), and then got another error involving the same line. I figured this was going to be something obnoxious. Thanks for spotting that, David!
Post Reply

Return to “General”