[What to note when using the ISXXX function in CType in the standard library]_[primary]_[]

Source: Internet
Author: User


Scene:

1. The functions in the ctype.h in the standard library are used for 1-byte judgments, but the parameters are int, which can easily lead to misuse.

Isalphaiscntrlisdigitisgraphisprintispunctisspaceisxdigit Isalnumislowerisupper

int isspace (int ch);

The most disgusting is the VC + + implementation will be more than 1 bytes of value will directly crash, GCC will not!!!

#if defined (_DEBUG) extern "C" int __cdecl _chvalidator (        int C,        int mask        ) {        _asserte ((unsigned) (C + 1) &l t;=);        Return _chvalidator_l (NULL, C, mask);}

So: When using these functions, remember to convert to unsigned char first

Isspace ((unsigned char) s);

What is the wrong use of isspace? One of the things I've come across is using isspace to judge wchar_t bytes, and if more than 255 crashes, you need to cast before using it.

Here the isspace can actually not be implemented by themselves, strong to (unsigned char) on the line, because we use the x86 architecture are low-byte order.

http://blog.csdn.net/infoworld/article/details/41981639



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

[What to note when using the ISXXX function in CType in the standard library]_[primary]_[]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.