简体   繁体   中英

Difference between byte and char in C

I am wondering why I can't compile an example from book. I simplify the example here to avoid posting example from a copyrighted book.

#include <stdio.h>

BYTE *data = "data";

int main()
{
     printf("%s", data);
     return 0;
}

When compile with g++, i get error,

error: invalid conversion from 'const char*' to 'BYTE*'

The program works by simply replacing BYTE with char, but I must be doing something wrong since the example comes from a book.

Please help pointing out the problem. Thanks.

BYTE isn't a part of the C language or C standard library so it is totally system dependent on whether it is defined after including just the standard stdio.h header file.

On many systems that do define a BYTE macro, it is often an unsigned char . Converting from a const char* to an unsigned char* would require an explicit cast.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM