[SOLVED] some c/c++ compiler shenanigans

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
austanss
Member
Member
Posts: 377
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

[SOLVED] some c/c++ compiler shenanigans

Post 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;
}
Last edited by austanss on Fri Nov 27, 2020 8:59 pm, edited 1 time in total.
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: some c/c++ compiler shenanigans

Post by Octocontrabass »

You have a local variable with the same name as the function you're trying to call.
User avatar
austanss
Member
Member
Posts: 377
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

Re: some c/c++ compiler shenanigans

Post by austanss »

Octocontrabass wrote:You have a local variable with the same name as the function you're trying to call.
thakns
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
Post Reply