adityanagal / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Function prototypes are generated, even if a function prototype already exists #973

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Make a typedef for a user type.
2. Make a function that takes that type as an argument.

What is the expected output? What do you see instead?

I get an error message, eg.

sketch_jul03a:-1: error: variable or field 'handler' declared void
sketch_jul03a:-1: error: 'tFoo' was not declared in this scope

However tFoo was declared in this scope.

What version of the Arduino software are you using? On what operating
system?  Which Arduino board are you using?

Version 1.0.1
OS/X
Board not relevant.

Please provide any additional information below.

Example sketch:

//------------------------------------------
typedef struct
  {
  int bar;
  } tFoo;

void handler (tFoo x)
  {
  x.bar = 42;  
  }

void setup ()
{
  tFoo a;
  handler (a);
}

void loop () {}
//------------------------------------------

I understand the IDE automatically generates function prototypes, and in the 
generated code they are put at the start. So the code submitted to the compiler 
is actually:

//------------------------------------------
#include "Arduino.h"
void handler (tFoo x);
void setup ();
void loop ();
typedef struct
  {
  int bar;
  } tFoo;

void handler (tFoo x)
  {
  x.bar = 42;  
  }
//------------------------------------------

Hence the error message. However if I attempt to work around this by generating 
my own function prototype in the right place, eg.

//------------------------------------------
typedef struct
  {
  int bar;
  } tFoo;

void handler (tFoo x);

void handler (tFoo x)
  {
  x.bar = 42;  
  }

void setup ()
{
  tFoo a;
  handler (a);
}

void loop () {}
//------------------------------------------

It still fails (the IDE still generates another prototype in the wrong place).

I suggest that the code for generating function automatic prototypes discards 
any prototypes for which one exists already.

Original issue reported on code.google.com by n...@gammon.com.au on 3 Jul 2012 at 6:04

GoogleCodeExporter commented 9 years ago
There are already several bug reports that at least in part if not entirely 
down to this issue.

There was a patch( 
https://github.com/EbiDK/Arduino/commit/96fc3c18c0cb118ec273947590e27114bfd7970d
 ) for it in a pull request( https://github.com/arduino/Arduino/pull/64 ) 5 
months ago, implementing this suggested solution, with mentions of the patch on 
the relevant other bug reports for the issue too.

Anyone else see something wrong with this picture?

Original comment by lars.j.n...@gmail.com on 9 Jul 2012 at 12:48

GoogleCodeExporter commented 9 years ago
By the way, most/all of the other reports can be found by searching for 
prototype on the bug tracker.

Original comment by lars.j.n...@gmail.com on 9 Jul 2012 at 12:49

GoogleCodeExporter commented 9 years ago
I searched for "prototype", naturally, to avoid submitting a duplicate bug 
report. None of the matches seemed relevant:

* Passing a pointer-to-struct to a function produces compile error   
* Prototypes for methods with default arguments are not generated    
* Stabilize the pre-processing of sketches (e.g. prototype generation and 
#include insertion).     
* odd pointer in verify 

> Anyone else see something wrong with this picture?

I don't know what you mean by that.

If you want to insult people submitting bug reports go right ahead, and I'll 
stop doing it.

Original comment by jainh...@gammon.com.au on 9 Jul 2012 at 9:31

GoogleCodeExporter commented 9 years ago
As an explanatory note, Google seems to have changed my email address. Not 
quite sure why, except that I logged into a different account on YouTube. Can't 
see the relevance to doing that, and submitting bug reports for the Arduino.

Original comment by jainh...@gammon.com.au on 9 Jul 2012 at 9:33

GoogleCodeExporter commented 9 years ago
https://github.com/arduino/Arduino/commit/d30bd8366074daa211433af7c32ee33f05fab2
8d

This is basically pull request #64, except I didn't add the "generated" prefix 
to the variable names.  Also, I changed the loop slightly to avoid problems 
with removing items from a list while iterating through it.  

Note that this patch requires your prototype to match the function definition 
exactly (including whitespace).  Otherwise, it won't realize they're the same.  
This could probably be improved but it does provide a way to stop the 
pre-processor from generating prototypes (which you couldn't do before).

Thank you Lars for the patch.  Thank you, Nick, too for this bug report.  Keep 
'em coming!

Original comment by dmel...@gmail.com on 19 Jul 2012 at 3:35