Why doesn't WiFi.BSSID() return a value?

Is there a reason why sometimes functions (or should i better say “procedures”) return a value and sometimes not?

E.g. string.getBytes(buf, len) - I would have expected that a “getBytes” function call will return “those bytes”. But I would not expect that this function call would write into the parameter “buf”.

WiFi.macAddress() on the other hand returns the MAC address.

While WiFi.BSSID(param) writes the MAC address back to the parameter.

Isn’t this very dangerous and confusing? Or, is there an important reason for doing so? Or, is it just legacy?


The WiFi.BSSID() function takes a pointer to a 6-byte buffer, not an object, so it can’t have a method like getBytes.

The API is that way because that’s the way it was defined for Arduino and we kept the API the same for compatibility.

1 Like

That’s why reading the docs is such a good habit :wink:

C/C++ often “only” returns a status about the execution of the function (AFAIK the term “procedure” isn’t commonly used in C/C++) - e.g. sprintf() by desing returns the number of successfully stored bytes instead of the buffer pointer itself, and that’s good so for validity checks.

In many cases there is no “pressing” reason for doing it one way or the other so it’s at the discretion of the (original) programmer but once a way has been taken it’s good practice to not break the behaviour and honour the legacy.

Thanks for the answers.