Skip to content

Emit a warning if a prototype is not generated due to known limitations #1944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
facchinm opened this issue Jul 8, 2016 · 1 comment
Open
3 tasks done
Labels
topic: build-process Related to the sketch build process topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@facchinm
Copy link
Member

facchinm commented Jul 8, 2016

Describe the request

Print a warning when necessary prototype generation for a function was intentionally skipped.

🙂 The user will have useful information about the cause of what would otherwise be a very mysterious compilation error.

Describe the current behavior

In order to make it easier for beginners to get started with writing Arduino sketches, and for the convenience of all users, Arduino CLI automatically generates and adds prototypes for functions defined in a .ino file of a sketch unless the sketch already contains that prototype.

Due to not needing to write them, and due to them not being mentioned anywhere in the official documentation of the Arduino Language, the average Arduino user does not know about function prototypes and takes forward declaration of their functions for granted.

In some cases, it might not be feasible for Arduino CLI to generate a prototype. For example, prototypes are intentionally not generated in the following cases:

Default parameter values

Prototypes are not generated for functions with default parameter values (arduino/Arduino#386):

if signatureContainsaDefaultArg(proto) {
continue
}

Compiling a sketch with a function using default parameter values that was referenced before declaration like this:

void setup() {
  foo();
}
void loop() {}
void foo(int bar = 42) {
  (void)bar;  // fix "unused parameter" warning
}

will fail:

C:\Users\per\Documents\Arduino\sketch_oct24a\sketch_oct24a.ino: In function 'void setup()':
C:\Users\per\Documents\Arduino\sketch_oct24a\sketch_oct24a.ino:2:3: error: 'foo' was not declared in this scope
   foo();
   ^~~

Namespaces

Prototypes are not generated for functions in namespaces (arduino/Arduino#5984):

if tag.Namespace != "" {
return false
}

Compiling a sketch with a function using default parameter values that was referenced before declaration like this:

namespace foo {
  void bar() {
    baz();
  }
  void baz() {}
}
void setup() {
  foo::bar();
}
void loop() {}

will fail:

C:\Users\per\Documents\Arduino\sketch_oct24a\sketch_oct24a.ino: In function 'void foo::bar()':
C:\Users\per\Documents\Arduino\sketch_oct24a\sketch_oct24a.ino:3:5: error: 'baz' was not declared in this scope
     baz();
     ^~~

Arduino CLI knows full well that it is omitting an essential prototype, yet doesn't make any effort to communicate that fact to the user.

🙁 The user will have great difficulty in determining the cause of the error and how to fix it. When the user asks for help on the forum, the programming wizards there will take great glee in the opportunity to gripe once again about how terrible of an idea prototype generation is.

Arduino CLI version

f239754

Operating system

All

Operating system version

Any

Additional context

Examples of where this has caused confusion for the users:


Originally suggested at arduino/Arduino#5103 (comment)

Additional Requests

Issue checklist

  • I searched for previous requests in the issue tracker
  • I verified the feature was still missing when using the latest nightly build
  • My request contains all necessary details
@nickgammon

This comment was marked as duplicate.

@per1234 per1234 added topic: code Related to content of the project itself type: enhancement Proposed improvement labels Oct 14, 2021
@per1234 per1234 transferred this issue from arduino/arduino-builder Oct 25, 2022
@per1234 per1234 added the topic: build-process Related to the sketch build process label Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: build-process Related to the sketch build process topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

3 participants