"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,872 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,782 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,834 Views
pb632146
Contributor V

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

0 Kudos
Reply
1,812 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,810 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,783 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
%3CLINGO-SUB%20id%3D%22lingo-sub-2026131%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%22Byte%20was%20not%20declared%20in%20this%20scope%22%20Trying%20to%20add%20c%2B%2B%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2026131%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20am%20trying%20to%20bring%20in%20c%2B%2B%20code%20from%20another%20project%20into%20a%20new%20one%2C%20but%20it%20is%20not%20recognizing%20%22byte%22s%2C%20The%20dialect%20is%20on%20c%2B%2B17%20so%20what%20should%20I%20do%3F%20I%20don't%20really%20want%20to%20convert%20everything%20to%20unsigned%20char%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22pb632146_1-1736576872192.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pb632146_1-1736576872192.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F319037i816E5C8A3F2BAF1B%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22pb632146_1-1736576872192.png%22%20alt%3D%22pb632146_1-1736576872192.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22pb632146_2-1736576976078.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pb632146_2-1736576976078.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F319038iEF58BBDE8289598B%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22pb632146_2-1736576976078.png%22%20alt%3D%22pb632146_2-1736576976078.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2028791%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20%22Byte%20was%20not%20declared%20in%20this%20scope%22%20Trying%20to%20add%20c%2B%2B%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2028791%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EOkay%20so%20it%20turns%20out%20that%20I%20should%20have%20noted%20that%20this%20is%20arduino%20code%20I%20am%20porting%20from%20%2C%20which%20uses%20byte%20as%20%22uint8_t.%22%20Thank%20you%20for%20the%20help%20though%20it%20turns%20out%20that%20using%20the%20actual%20cstddef%20would%20be%20incorrect%20in%20this%20situation.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2028547%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20%22Byte%20was%20not%20declared%20in%20this%20scope%22%20Trying%20to%20add%20c%2B%2B%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2028547%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EI%20see%2C%20do%20I%20need%20to%20add%20std%3A%3A%20on%20to%20all%20the%20byte%20declarations%3F%20or%20is%20there%20a%20define%20I%20can%20do%20to%20avoid%20finding%20and%20adding%20every%20instance%20of%20byte%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2027106%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20%22Byte%20was%20not%20declared%20in%20this%20scope%22%20Trying%20to%20add%20c%2B%2B%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2027106%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EAny%20suggestion%20on%20what%20to%20do%20to%20make%20the%20compiler%20see%20byte%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2026154%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20%22Byte%20was%20not%20declared%20in%20this%20scope%22%20Trying%20to%20add%20c%2B%2B%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2026154%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F230291%22%20target%3D%22_blank%22%3E%40pb632146%3C%2FA%3E%2C%3CBR%20%2F%3E%3CSPAN%3EIn%20C%2B%2B17%2C%20std%3A%3Abyte%20was%20introduced%20as%20part%20of%20the%20standard%20library%20to%20represent%20raw%20byte%20data.%20If%20your%20code%20isn't%20recognizing%20byte%2C%20ensure%20you%20are%20including%20the%20correct%20header%3A%3C%2FSPAN%3E%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3Ecpp%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CDIV%3E%3CPRE%3E%3CSPAN%3E%23include%20%3CCSTDDEF%3E%20%2F%2F%20for%20std%3A%3Abyte%3C%2FCSTDDEF%3E%3C%2FSPAN%3E%0A%3C%2FPRE%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%3CSPAN%3EBy%20including%20this%20header%2C%20your%20project%20should%20properly%20recognize%20std%3A%3Abyte.%20This%20eliminates%20the%20need%20to%20convert%20every%20instance%20to%20unsigned%20char.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3EBest%20Regards%2C%3CBR%20%2F%3EJames%20Henry%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E