Skip to content

Function with default parameter doesn't get it's prototype in *.h header file. #39

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

Closed
ffissore opened this issue Oct 30, 2015 · 5 comments
Assignees
Milestone

Comments

@ffissore
Copy link
Contributor

From @obiwan-bartek on October 30, 2015 0:20

When you write a function with at least one parameter with default value
eg.

void foo(int a, int b = 0)
{
}

it does not gets generated it's prototype in header file, which results in an unreferenced calls in project to that function. When you remove the default parameter

 = 0

the prototype shows in header file as expected.

Copied from original issue: arduino/Arduino#4048

@ffissore
Copy link
Contributor Author

From @NicoHood on October 30, 2015 7:24

You need to do:

// prototype
void foo(int a, int b = 0);

// Implementation, better place inside a .cpp or marke the prototype above as static inline
void foo(int a, int b)
{

}

@ffissore
Copy link
Contributor Author

@obiwan-bartek as @NicoHood said, you have to write the prototype on your own. Current implementation is unable to handle default parameters (see #23). Correct prototype generation includes moving the default value from the function implementation to the prototype: this is something we can't do at the moment

@ffissore ffissore added this to the 1.0.4 milestone Oct 30, 2015
@ffissore ffissore self-assigned this Oct 30, 2015
@NicoHood
Copy link

I answered this because he was talking about .h files. In previous version of the IDE it was possible in .ino files. Since I dont know much about the .ino file generation I dont want to answer to this. I also dont like to code inside .ino files with more complex stuff. Normally I use libraries for this, so I dont care about such features.

@matthijskooijman
Copy link
Collaborator

Yeah, the old regex-based implementation tried harder to get correct prototypes, but also regularly messed up. The new ctags-based approach only tries for the easy functions (no attributes, no inline, no function pointers, no default arguments) so it will at least generate working code. If you use more complex stuff, you'll have to take care of the prototypes (or proper ordering) yourself.

@NicoHood
Copy link

I think thats okay if it then enables stuff like templates which made a lot of problems before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants