Reference to 'byte' is ambiguous

Hi! I'm trying to upload code from ESP-1ch-Gateway . This is error what I have and I can't figure out what is the problem. I did it before from my laptop with same Wemos D1 mini and all libraries and this code without any problems. Everithing works fine. But this time from other computer it won't to work.

C:\Users\y.heninsh\Documents\Arduino\ESP-1ch-Gateway-master\ESP-sc-gway\_utils.ino: In function 'int getNtpTime(time_t*)':
_utils:474:2: error: reference to 'byte' is ambiguous
  474 |  byte packetBuffer[NTP_PACKET_SIZE];
      |  ^~~~
In file included from c:\users\y.heninsh\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\cmath:42,
                 from c:\users\y.heninsh\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\math.h:36,
                 from C:\Users\y.heninsh\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/Arduino.h:34,
                 from sketch\ESP-sc-gway.ino.cpp:1:
c:\users\y.heninsh\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\bits\cpp_type_traits.h:404:30: note: candidates are: 'enum class std::byte'
  404 |   enum class byte : unsigned char;
      |                              ^~~~
In file included from sketch\ESP-sc-gway.ino.cpp:1:
C:\Users\y.heninsh\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/Arduino.h:160:17: note:                 'typedef uint8_t byte'
  160 | typedef uint8_t byte;
      |                 ^~~~
_utils:475:9: error: 'packetBuffer' was not declared in this scope
  475 |  memset(packetBuffer, 0, NTP_PACKET_SIZE);    // Set buffer contents to zero
      |         ^~~~~~~~~~~~
exit status 1
reference to 'byte' is ambiguous

change 'byte' to 'unsigned char'

Or change 'byte' to 'uint8_t'.

A definition of 'byte' got added to 'cmath' in the ESP8266 standard libraries and it conflicts with the declaration of 'byte' in Arduino.h.

Do you have using namespace std; in your code (or libraries) somewhere?

Yes. There is using namespace std;

That is bad practice, and the cause of your error.

See c++ - Why is "using namespace std;" considered bad practice? - Stack Overflow

If you need a standard library name a handful of times, write it in full, e.g.

std::vector<int> v; // good
// ---
using namespace std; // bad, pulls in all names from the std namespace
vector<int> v;

If you need the same name many times and want to save on typing, you could use specific using directives:

using std::vector; // okay
vector<int> v;

You probably don't want to do this inside of a public header of a library, but in your own code, it's mostly harmless.

If the scope is limited, using namespace isn't harmful either, e.g.

void some_function() {
  using namespace std; // okay
  vector<int> v; 
}

If you want to avoid typing long namespace names, you can create an alias:

std::filesystem::path p = "..."; // long
// ---
namespace fs = std::filesystem;
fs::path p = "..."; // easier to read and type

I solved my problem with not the best way I think, but it's works. I uninstaled esp8266 board meneger latest varsion 3.0.2 and instaled 2.7.4. Added few libraries and it's work right now.

This is a nonsolution. Newer versions of the Core include bug fixes and use better compilers. You'll have to update eventually, so you might as well fix your code now.

Multiple solutions have been given: use uint8_t instead of byte and avoid using namespace std.

1 Like

This is not my code. I'm using ESP-1ch-Gateway-v5.0--OLD. I don't have a time right now to change every byte and to avoid using namespace std. But of course You are right! Thank You!

Perhaps it is time to consider the current version:

1 Like

In the past, jobs like that have taken me only a minute or two, using global search and replace. If it's not as unique as "byte", I do a find and replace, with visual confirmation.

1 Like

Of course I will try 6.0 version! Do You have experience with this?

No experience. I just noticed that the library you pointed to had "--OLD" at the end of the name and hadn't been changed in two years.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.