c - 得到 "error: expected identifier or ' ('"

标签 c

// triangle.h
struct posn {
  int x;
  int y;
};

// struct is_right_triangle(p1, p2, p3) 
struct is_right_triangle(const struct posn *p1, const struct posn *p2, 
const struct posn *p3);



struct is_right_triangle(const struct posn *p1, const struct posn *p2,
 const struct posn *p3) {
  const int a = (p1->x - p2->x)*(p1->x - p2->x) + (p1->y - p2->y)*(p1->y - p2->y);
  const int b = (p1->x - p3->x)*(p1->x - p3->x) + (p1->y - p3->y)*(p1->y - p3->y);
  const int c = (p3->x - p2->x)*(p3->x - p2->x) + (p3->y - p2->y)*(p3->y - p2->y);
  if (a + b == c) {
    return *p1;
  } else if (b + c == a) {
    return *p2;
  } else if (a + c == b)  {
    return *p3;
  } else {
    return NULL;
  }
}

为什么我会收到此错误:

./triangle.h:13:26: error: expected identifier or '(' struct is_right_triangle(const
              struct posn *p1, const struct posn *p2, const struct posn *p3); ^ 
./triangle.h:13:26: error: expected ')' 
./triangle.h:13:25: note: to match this '(' struct is_right_triangle(const struct posn *p1, const struct posn *p2, const struct posn *p3);

最佳答案

您没有指定要返回哪种类型的结构。试试这个:

const struct posn *is_right_triangle(const struct posn *p1, const struct posn *p2, const struct posn *p3) {

关于c - 得到 "error: expected identifier or ' ('",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19396098/

相关文章:

c - x86 Assembly Force 高速缓存存储

java - C 中的 eval 函数结果为负

c - 举例说明在 C 中扫描一个字符

c - 在 c 代码中显示溢出的工具

c - 访问 C vector 中的写入违规

c - 结构元素测试为空

c - 将 32 位指令拆分为字节并使用 c 将结果移动到另一个地址

android - 如何理解这个定义宏?

C time.h环绕

c - 将程序设置为我的登录 shell