开发者

c++ syntax error when declaring an array of bytes

开发者 https://www.devze.com 2023-03-23 20:36 出处:网络
Im trying to declare an array of bytes so I can go through them and use each one of them seperatly. This is the array

Im trying to declare an array of bytes so I can go through them and use each one of them seperatly. This is the array

const BYTE keybyte[] = {
    0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
    0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
    0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 0x58,
    0x59, 0x5A, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
    0x36, 0x37, 0x38, 0x39, 0x25, 0x27, 0x26, 0x28,
    0x0D, 0x20, 0x10, 0x11, 0x12, 0x18};

For some reason when I compile it gives me these errors :/

error C2143: 开发者_JAVA百科syntax error : missing '}' before 'constant'
error C2143: syntax error : missing ';' before 'constant'
error C2059: syntax error : 'constant'
error C2143: syntax error : missing ';' before '}'
error C2059: syntax error : '}'

I dont understand because if I replace it with

const BYTE keybyte[] = {0,0,0,0};

it works perfectly fine with no errors :/?


You are missing a comma between 0x57 and 0x58.


Alexander Gessler is right - comma is missing. Next Time try compile file with gcc and clang. It will guide you to problem resolution:

For file test.h containing:

const char keybyte[] = {0x41, 0x42, 0x43 0x44, 0x45, 0x12, 0x18};

when I try GCC:

test.h:1:42: error: expected ‘}’ before numeric constant

Compilers parser says, the syntax is wrong on the line 1 and the character 42:

When I ask clang, I get even better output:

clang test.h
test.h:1:42: error: expected '}'
const char keybyte[] = {0x41, 0x42, 0x43 0x44, 0x45, 0x12, 0x18};
                                         ^

so I see where the problem is.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号