user23959: I declared my enum and called it Dir. I wanted to use value of that type in my function Move(). Here's the code:
enum Dir
{
  forward = 1,
  backward = 2,
  left = 3,
  right = 4
};

void Move ( Dir direction , int distance )
{
     direction = forward;
}


void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Unfortunately i get the following errors:
V2.ino:23:13: error: variable or field 'Move' declared void
V2.ino:23:13: error: 'Dir' was not declared in this scope
V2.ino:23:29: error: expected primary-expression before 'int'

What's wrong?

user25571: As Majenko points out, this seems to be a problem with the parsing of the preprocessor.
You have two options:


Use Edgar Bonets solution and declare the function before defining it


Create a separate header file for your enum in a new tab and import it with #include "[myEnumsHeaderFilename].h"

#include "myEnums.h"


void Move(Dir direction, int distance)
{
   direction = forward; 
}

void setup() {}

void loop() {}


user7508: I did not experience the problem because I usually use a Makefile instead of
the Arduino IDE. I now tried with the IDE version 1.0.5 and I had the same
problem as you. The fix is to explicitly declare the function before
defining it:
void Move(Dir direction, int distance);
void Move(Dir direction, int distance)
{
     direction = forward;
}


user4143: The Arduino 1.7.x series from Arduino.org uses the old build system that is severely broken when you try and do anything more complex than simple types.
It adds prototypes to your functions to the top of the program so you don't have to get the order right, but it puts them in completely the wrong place.  The result is a C++ file that looks like this:
#include <Arduino.h>
void Move ( Dir direction , int distance );
void setup();
void loop();

enum Dir
{
  forward = 1,
  backward = 2,
  left = 3,
  right = 4
};

void Move ( Dir direction , int distance )
{
     direction = forward;
}

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

As you can see the prototype involving Dir has been placed before the definition of Dir, and so it fails miserably.
There are some hacks you can do to force it to place the prototypes after your definition, but I can't recall what they are off hand.
The simple answer is to ditch Arduino 1.7.10 and switch to Arduino 1.6.10 from Arduino.cc instead. This uses the Arduino Builder system which does things much better, including placing the prototypes in the right place.
Despite the numbering 1.7.10 is not a newer version than 1.6.10 - it is an older version renumbered. It's all part of the schism between the two halves of Arduino.
Even better is to ditch the awful Arduino IDE entirely and use one of the many far better IDEs that exist.

23959: <p>I declared my enum and called it Dir. I wanted to use value of that type in my function Move(). Here's the code:</p>

<pre><code>enum Dir
{
  forward = 1,
  backward = 2,
  left = 3,
  right = 4
};

void Move ( Dir direction , int distance )
{
     direction = forward;
}


void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}
</code></pre>

<p>Unfortunately i get the following errors:</p>

<pre><code>V2.ino:23:13: error: variable or field 'Move' declared void
V2.ino:23:13: error: 'Dir' was not declared in this scope
V2.ino:23:29: error: expected primary-expression before 'int'
</code></pre>

<p>What's wrong?</p>
 25571: <p>As Majenko points out, this seems to be a problem with the parsing of the preprocessor.</p>

<p>You have two options:

<li>
Use Edgar Bonets solution and declare the function before defining it
</li>
<li>
Create a separate header file for your enum in a new tab and import it with #include "[myEnumsHeaderFilename].h"
</li></p>

<pre><code>#include "myEnums.h"


void Move(Dir direction, int distance)
{
   direction = forward; 
}

void setup() {}

void loop() {}
</code></pre>
 7508: <p>I did not experience the problem because I usually use a Makefile instead of
the Arduino IDE. I now tried with the IDE version 1.0.5 and I had the same
problem as you. The fix is to explicitly declare the function before
defining it:</p>

<pre class="lang-c++ prettyprint-override"><code>void Move(Dir direction, int distance);
void Move(Dir direction, int distance)
{
     direction = forward;
}
</code></pre>
 4143: <p>The Arduino 1.7.x series from Arduino.org uses the old build system that is severely broken when you try and do anything more complex than simple types.</p>

<p>It adds prototypes to your functions to the top of the program so you don't have to get the order right, but it puts them in completely the wrong place.  The result is a C++ file that looks like this:</p>

<pre><code>#include &lt;Arduino.h&gt;
void Move ( Dir direction , int distance );
void setup();
void loop();

enum Dir
{
  forward = 1,
  backward = 2,
  left = 3,
  right = 4
};

void Move ( Dir direction , int distance )
{
     direction = forward;
}

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}
</code></pre>

<p>As you can see the prototype involving <code>Dir</code> has been placed before the definition of <code>Dir</code>, and so it fails miserably.</p>

<p>There are some hacks you can do to force it to place the prototypes after your definition, but I can't recall what they are off hand.</p>

<p>The simple answer is to ditch Arduino 1.7.10 and switch to Arduino 1.6.10 from Arduino.cc instead. This uses the Arduino Builder system which does things much better, including placing the prototypes in the right place.</p>

<p>Despite the numbering 1.7.10 is not a newer version than 1.6.10 - it is an older version renumbered. It's all part of the schism between the two halves of Arduino.</p>

<p>Even better is to ditch the awful Arduino IDE entirely and use one of the many far better IDEs that exist.</p>
