Problem with arduino 0022 IDE

for some reason if my code starts out with "#define" I get the following error.

In file included from C:\Users\Mike\Desktop\arduino-0022\hardware\arduino\cores\arduino/WProgram.h:10,
from sketch_mar12a.cpp:7:
C:\Users\Mike\Desktop\arduino-0022\hardware\arduino\cores\arduino/wiring.h:122: error: expected ',' or '...' before numeric constant
C:\Users\Mike\Desktop\arduino-0022\hardware\arduino\cores\arduino/wiring.h:123: error: expected ',' or '...' before numeric constant

but if I just put an arbitrary piece of code, for example, byte a = 0; above the #define section the code compiles correctly.

This codes doesn't compile:

#define latchPin 7
#define dataPin  9
#define clockPin 8

//byte switchVar1 = 72;  //01001000

void setup() {
  Serial.begin(9600);
  pinMode(latchPin, INPUT);
  pinMode(clockPin, OUTPUT); 
  pinMode(dataPin, INPUT);
}
void loop() {
  if (digitalRead(latchPin) == HIGH){
    while(digitalRead(latchPin) == HIGH){
      delay(1);
    }
    if (digitalRead(latchPin) == LOW){
      byte myDataIn = 0;
      for (int i=0; i<8; i++){
        digitalWrite(clockPin, 0);
        delayMicroseconds(0.2);
        if (digitalRead(dataPin)) {
          myDataIn = myDataIn | (1 << i);
        }
        digitalWrite(clockPin, 1);
      }
      Serial.println(myDataIn,BIN);
    }
  }
}

This works:

byte a=0;
#define latchPin 7
#define dataPin  9
#define clockPin 8

//byte switchVar1 = 72;  //01001000

void setup() {
  Serial.begin(9600);
  pinMode(latchPin, INPUT);
  pinMode(clockPin, OUTPUT); 
  pinMode(dataPin, INPUT);
}
void loop() {
  if (digitalRead(latchPin) == HIGH){
    while(digitalRead(latchPin) == HIGH){
      delay(1);
    }
    if (digitalRead(latchPin) == LOW){
      byte myDataIn = 0;
      for (int i=0; i<8; i++){
        digitalWrite(clockPin, 0);
        delayMicroseconds(0.2);
        if (digitalRead(dataPin)) {
          myDataIn = myDataIn | (1 << i);
        }
        digitalWrite(clockPin, 1);
      }
      Serial.println(myDataIn,BIN);
    }
  }
}

Any ideas why this is so?

It's a consequence of the way the IDE figures out how to insert the prototypes that it generates...

What does that mean in simple-human language? Was that useless variable "byte a=0" introduction only difference between those two codes?
:astonished:

Cheers,
Kari

The IDE adds the include files (WProgram.hmw which includes wiring.h) before the "first line of C" that it sees, but it does not include the "#define" lines in its definition of "lines of C" (exact reason unknown.) So the constructed program ends up containing:

#define latchPin 7
#define dataPin  9
#define clockPin 8

//byte switchVar1 = 72;  //01001000

#include "WProgram.h"

Now, line 122 of wiring.h is:void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
Since you've #defined some of those same names, this becomes an illegal statement ("shiftout(uint8_t 9, ...")

Normally, if you were writing code yourself, your particular #defines would come after all the system includes, and you wouldn't have this problem. Probably if more warnings were enabled, you would have seen a "symbol redefined" warning...

I've had errors messages very similar to yours before, and if I move the #include's before the #define in my code, it compiles just fine after that.

There is, as you've discovered, a reason for the convention that #define'd names, and only #define'd names, be all capital letters. Since names are case-sensitive, clockpin, CLOCKPIN, and clockPin are all different names.

So, had you followed the convention, you would not have generated a name conflict.