Page 1 of 1

[SOLVED] some c/c++ compiler shenanigans

Posted: Fri Nov 27, 2020 8:47 pm
by austanss
I'm really fucking tired. Like, really tired. I've fixed so many bugs today and written so many minor features that I'm exhausted. So forgive me if I'm overlooking something, OK?

This function:

Code: Select all

void rect(positional_point pos, dimensions dims, uint32_t color) {

	for (uint32_t xx = pos.x; (xx <= (pos.x + dims.w)) && (xx < width); xx++)
		for (uint32_t yy = pos.y; (yy <= (pos.y + dims.h)) && (yy < height); yy++)
			plot_pixel(pos(xx, yy), color);

	buff();
}
Gives this error:

Code: Select all

src/gfx.cxx:33:25: error: no match for call to ‘(positional_point {aka s_pos_point}) (uint32_t&, uint32_t&)’
   33 |    plot_pixel(pos(xx, yy), color);
      |                         ^
Which insinuates that xx[/i[ and yy are references, which is so not good on so many levels.
This seems to be out of my control, though is there any compiler flags to fix this, or is my code wrong?

Referenced functions/structs:

Code: Select all

typedef struct s_pos_point {
	int x;
	int y;
} positional_point;

typedef struct s_dimensions {
	int w;
	int h;
} dimensions;

positional_point pos(int x, int y) {

	positional_point pos;
	pos.x = x;
	pos.y = y;
	return pos;
}

void plot_pixel(positional_point pos, uint32_t pixel)
{
	*((uint32_t*)(gop.framebuffer_base_addr + 4 * gop.pixels_per_scan_line * pos.y + 4 * pos.x)) = pixel;
}

Re: some c/c++ compiler shenanigans

Posted: Fri Nov 27, 2020 8:54 pm
by Octocontrabass
You have a local variable with the same name as the function you're trying to call.

Re: some c/c++ compiler shenanigans

Posted: Fri Nov 27, 2020 8:55 pm
by austanss
Octocontrabass wrote:You have a local variable with the same name as the function you're trying to call.
thakns