-
-
Notifications
You must be signed in to change notification settings - Fork 414
Not planned
Not planned
Copy link
Labels
conclusion: duplicateHas already been submittedHas already been submittedtopic: build-processRelated to the sketch build processRelated to the sketch build processtopic: codeRelated to content of the project itselfRelated to content of the project itselftype: imperfectionPerceived defect in any part of projectPerceived defect in any part of project
Description
The type declared after any function is not visible as the parameter type for any other function below.
Although it is suitable for other purposes.
For example:
struct tword{
byte low;
byte high;
};
void none(){}
bool test(tword par){return true;}
void setup() {
word w;
tword* var = (tword*)(&w);
}
void loop(){}
It's ok.
void none(){}
struct tword{
byte low;
byte high;
};
//bool test(tword par){return true;}
void setup() {
word w;
tword* var = (tword*)(&w);
}
void loop(){}
Too it's ok
void none(){}
struct tword{
byte low;
byte high;
};
bool test(tword par){return true;}
void setup() {
word w;
tword* var = (tword*)(&w);
}
void loop(){}
Compilation fails with the error:
'tword' was not declared in this scope
Additional context
Additional reports
Metadata
Metadata
Assignees
Labels
conclusion: duplicateHas already been submittedHas already been submittedtopic: build-processRelated to the sketch build processRelated to the sketch build processtopic: codeRelated to content of the project itselfRelated to content of the project itselftype: imperfectionPerceived defect in any part of projectPerceived defect in any part of project
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
per1234 commentedon Apr 18, 2021
Hi @allnick. Thanks for your report.
During sketch preprocessing, the Arduino build system (which is implemented here in the Arduino CLI code base) automatically generates function prototypes in .ino files for any functions that don't already have a prototype. This turns out to be surprisingly difficult. Although the prototype generation system works fine for most sketches, under certain circumstances, it inserts the prototype at the wrong position in the code. That is the cause of the error you encountered.
You can see how the code looks after preprocessing here:
Note that the
bool test(tword par);
prototype was inserted above the declaration of thetword
type.The workaround is to simply manually add your own prototype in the correct location:
allnick commentedon Apr 18, 2021
Respected per1234. Thanks for your explanation.
But I just moved the type declaration above all the functions.
But your remark, I necessarily take into account.
7 remaining items