Astroloico
Astroloico

Reputation: 11

Getting two C compiler errors while calling a function (too few args and expected element before)

So, I am currently writing a rasterization-based 3D renderer with raylib in C, and I got three errors, and I have no clue where they came from.

function itself:

float triArea(point a, point b, point c) {
    point midPoint = point((a.x + b.x) * 0.5, (a.y + b.y) * 0.5);
    float base = distance(a, b);
    float height = distance(midPoint, c);
    return base * height * 0.5;
}

place with the error:

for (int x = 0; x < dx; x++) {
    for (int y = 0; y < dy; y++) {
        DrawPixel(x, y, getColor(0xffffff * isInTri(
            point(x, y),
            point(100, 0),
            point(100, 100),
            point(0, 100)
        )));
    }
}

the 'point' struct:

struct v2 {
    float x;
    float y;
};
typedef struct v2 point;

the errors I got:

main.c: In function 'main':
main.c:46:21: error: expected expression before 'point'
   46 |                     point(x, y),
      |                     ^~~~~
main.c:45:53: error: too few arguments to function 'isInTri'
   45 |                 DrawPixel(x, y, getColor(0xffffff * isInTri(
      |                                                     ^~~~~~~
main.c:27:6: note: declared here
   27 | bool isInTri(point p, point a, point b, point c) {
      |      ^~~~~~~

I am new to C and programming in general.

I replaced all the 'point(...)' to 'point{...}' but I didn't change anything.

Upvotes: 1

Views: 62

Answers (1)

gnasher729
gnasher729

Reputation: 52612

As a rule, look at the very first error only and fix it.

“point” is the name of a type. point(x, y) has no meaning whatsoever in C. It’s not C++. You could write a function point makepoint (int x, int y) and call that.

Upvotes: 2

Related Questions