谁决定字符的顺序 [英] Who determines the ordering of characters

查看:84
本文介绍了谁决定字符的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于以下程序查询 -

I have a query based on the below program -

char ch;
ch = 'z';
while(ch >= 'a')
{
    printf("char is  %c and the value is %d\n", ch, ch);
    ch = ch-1;
}

为什么是一整套在上面的程序不能保证小写字母的印刷。如果C不做出关于内部形式的字符的顺序许多保障,那么究竟是谁做,以及如何?

Why is the printing of whole set of lowercase letters not guaranteed in the above program. If C doesn't make many guarantees about the ordering of characters in internal form, then who actually does it and how ?

推荐答案

编译器实现者选择他们的基本字符集。有关标准不得不说的唯一的事情就是特定字符最少数量必须是可用的,而且数字字符是连续的。

The compiler implementor chooses their underlying character set. About the only thing the standard has to say is that a certain minimal number of characters must be available and that the numeric characters are contiguous.

对于C99执行环境所需的字符是 A 以Z A 以Z 0 9 (必须是在一起,按顺序),任何的#%&放大器;'()* +, - 。/:;!?< => [\\] ^ _ {|} 〜,空间,水平制表符,垂直制表符,换页,报警,退格,回车和新的生产线,这仍然是C1X,该标准的下一次迭代的目前的草案不变。

The required characters for a C99 execution environment are A through Z, a through z, 0 through 9 (which must be together and in order), any of !"#%&'()*+,-./:;<=>?[\]^_{|}~, space, horizontal tab, vertical tab, form-feed, alert, backspace, carriage return and new line. This remains unchanged in the current draft of C1x, the next iteration of that standard.

其他一切依赖于实现。

例如,code,如:

int isUpperAlpha(char c) {
    return (c >= 'A') && (c <= 'Z');
}

将打破它采用EBCDIC,划分大写字母分为两个区域的主机。

will break on the mainframe which uses EBCDIC, dividing the upper case characters into two regions.

真正的便携式code会考虑到这一点。所有其他code应该记录其相关性。

Truly portable code will take that into account. All other code should document its dependencies.

一个更便携实现你的榜样将是沿着线的东西:

A more portable implementation of your example would be something along the lines of:

static char chrs[] = "zyxwvutsrqponmlkjihgfedcba";
char *pCh = chrs;
while (*pCh != 0) {
    printf ("char is %c and the value is %d\n", *pCh, *pCh);
    pCh++;
}

如果你想要一个的真正的便携式解决方案,您应该使用 islower判断()自code,检查只有拉丁字符赢得'T移植到(例如)希腊统一使用code作为它的底层字符集。

If you want a real portable solution, you should probably use islower() since code that checks only the Latin characters won't be portable to (for example) Greek using Unicode for its underlying character set.

这篇关于谁决定字符的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆