If you take the code posted above, and compile it for a Mega, you should see this:
Arduino: 1.6.12 (Linux), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
/tmp/ccNfzOpl.ltrans0.ltrans.o: In function `main':
ccNfzOpl.ltrans0.o:(.text.startup+0x202): undefined reference to `loop'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
If you put in a dummy loop
void setup() {
Serial.begin(115200);
passcodeCheck();
}
const int passcode = 1324;
int access = 0;
int incomingByte = Serial.read();
void passcodeCheck() {
Serial.print("Enter Passcode: ");
Serial.print(incomingByte);
}
void loop (){} // <<< I ADDED THIS
and compiled it, again, for a Mega, you should see this message Sketch uses 2,090 bytes (0%) of program storage space. Maximum is 253,952 bytes.
Global variables use 204 bytes (2%) of dynamic memory, leaving 7,988 bytes for local variables. Maximum is 8,192 bytes.
.
The only way I can see that you could get a error for Serial not being defined, would be if you compiled the code for a processor that doesn't have a UART.