![](/img/trans.png)
[英]Implicit declaration of function in main/error:expected ';', ',' or ')' before numeric constant|
[英]Implicit declaration of function, expected ‘;’, ‘,’ or ‘)’
編譯器給出錯誤,如下所示。 據我所知,常量以及函數調用均正確聲明。 該程序將計算三角形的面積和周長,並使用5個不同的函數。 任何幫助,將不勝感激。
program05.c:16:22: error: expected ‘;’, ‘,’ or ‘)’ before 'A'
#define SIDE_1_LABEL 'A'
^
program05.c:20:25: note: in expansion of macro ‘SIDE_1_LABEL’
float getUserValue(char SIDE_1_LABEL, char SIDE_2_LABEL);
^
program05.c: In function ‘main’:
…
#include <stdio.h>
#include <math.h>
#define SIDE_1_LABEL 'A'
#define SIDE_2_LABEL 'B'
void printInstructions();
float getUserValue(char SIDE_1_LABEL, char SIDE_2_LABEL);
float calculateArea(float side1, float side2);
float calculatePerimeter(float side1, float side2);
void printResults(float side1, float side2, float area, float perimeter);
int main()
{
…
你寫了:
#define SIDE_1_LABEL 'A'
#define SIDE_2_LABEL 'B'
float getUserValue(char SIDE_1_LABEL, char SIDE_2_LABEL);
那和寫完全一樣:
float getUserValue(char 'A', char 'B');
這顯然是無效的,因為'A'和'B'不是變量名。
如果您不知道,則宏擴展的工作原理就好像您確實在宏出現的所有位置都將其粘貼復制了宏定義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.