PaulS:
It does not. The IDE does, when it can, before it invokes the compiler which has a preprocessor phase.
What I meant...
PaulS:
It also allows them to be declared before main().
Also what I meant... a declaration is not required if functions are defined before main() or before being called.
PaulS:
In my opinion, that is a piss-poor idea.
... to be able to run the program in other IDEs or compilers... with regard to my previous statement.
PaulS:
The Serial object is an instance of the HardwareSerial class, which derives from Print. Look at how Print declares, and implements, the print() method. There are no shortcuts.
I do not understand, sorry...
...
MorganS:
You can have functions which accept differently typed parameters.
Thank you for your nice and helpful explanation!
I have, in the meantime created the function below, to help with debugging and display the result, which I did previously like so:
Serial.print(F("IP Address client ...........: "));
Serial.println(Ethernet.localIP());
#include <SPI.h> // required for EtherShield
#include <Ethernet.h> // Ethernet Library for EtherShiled
byte MAC_ADDRESS[] = { 0x4D, 0x61, 0x78, 0x47, 0x39, 0x37 }; // 6 hex digit MAC: reads MaxG97
EthernetClient ethClient; // Ethernet
void setup() {
Serial.begin(9600);
}
void loop() {
while(1) {
void serialPrint("IP Address client", Ethernet.localIP());
}
}
void serialPrint(String itemName, char itemValue) {
byte itemColumnLength = 50;
byte itemNameLength = itemName.length();
byte numberOfDots = itemColumnLength - itemNameLength - 2;
String dots = "";
for (byte i = 0; i <= numberOfDots; i++) {
dots = dots + ".";
}
Serial.println(F(String(itemName + " " + dots + ": " + itemValue + "\n")));
}
However, it complains by saying this:
D:\MaxG_MyDocuments\Arduino\zTests\serialPrintV0\serialPrintV0.ino: In function 'void loop()':
serialPrintV0:13: error: variable or field 'serialPrint' declared void
void serialPrint("IP Address client", Ethernet.localIP());
^
In file included from C:\Users\MaxG\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.16\cores\arduino/Arduino.h:28:0,
from sketch\serialPrintV0.ino.cpp:1:
D:\MaxG_MyDocuments\Arduino\zTests\serialPrintV0\serialPrintV0.ino: In function 'void serialPrint(String, char)':
C:\Users\MaxG\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.16\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
^
D:\MaxG_MyDocuments\Arduino\zTests\serialPrintV0\serialPrintV0.ino:28:18: note: in expansion of macro 'F'
Serial.println(F(String(itemName + " " + dots + ": " + itemValue + "\n")));
^
C:\Users\MaxG\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.16\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
^
D:\MaxG_MyDocuments\Arduino\zTests\serialPrintV0\serialPrintV0.ino:28:18: note: in expansion of macro 'F'
Serial.println(F(String(itemName + " " + dots + ": " + itemValue + "\n")));
^
exit status 1
variable or field 'serialPrint' declared void