"Byte was not declared in this scope" Trying to add c++ file

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"Byte was not declared in this scope" Trying to add c++ file

Jump to solution
1,446 Views
pb632146
Contributor V

I am trying to bring in c++ code from another project into a new one, but it is not recognizing "byte"s, The dialect is on c++17 so what should I do? I don't really want to convert everything to unsigned char

pb632146_1-1736576872192.png

pb632146_2-1736576976078.png

 

0 Kudos
Reply
1 Solution
1,356 Views
pb632146
Contributor V
Okay so it turns out that I should have noted that this is arduino code I am porting from , which uses byte as "uint8_t." Thank you for the help though it turns out that using the actual cstddef would be incorrect in this situation.

View solution in original post

0 Kudos
Reply
4 Replies
1,408 Views
pb632146
Contributor V

Any suggestion on what to do to make the compiler see byte?

0 Kudos
Reply
1,386 Views
james246henry
Contributor I

Hello @pb632146,
In C++17, std::byte was introduced as part of the standard library to represent raw byte data. If your code isn't recognizing byte, ensure you are including the correct header:

cpp
#include <cstddef> // for std::byte

By including this header, your project should properly recognize std::byte. This eliminates the need to convert every instance to unsigned char.


Best Regards,
James Henry

0 Kudos
Reply
1,384 Views
pb632146
Contributor V
I see, do I need to add std:: on to all the byte declarations? or is there a define I can do to avoid finding and adding every instance of byte
0 Kudos
Reply
1,357 Views
pb632146
Contributor V
Okay so it turns out that I should have noted that this is arduino code I am porting from , which uses byte as "uint8_t." Thank you for the help though it turns out that using the actual cstddef would be incorrect in this situation.
0 Kudos
Reply