这个关于char指针的引用是什么意思? [英] What does this quote about char pointers mean?

查看:211
本文介绍了这个关于char指针的引用是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过一段,但我不明白这是什么意思....任何人都可以解释一下吗?段落是:

I've read a paragraph but I can't understand what does it mean....can anyone please explain? the paragraph is :


将单个字符处理为
char *字符串可能导致致命的
运行时错误。 char *字符串是一个
指针,可能是一个大的整数。
但是一个字符是一个小的
整数(ascii 0-255)。在许多系统上,
dereferencing一个char vaalue导致
错误,因为低内存地址
保留为特殊目的,如
作为操作系统中断
处理程序 - 所以内存冲突

processing a single character as a char*string can lead to a fatal runtime error. a char* string is a pointer probably a large integer. however a character is a small integer(ascii 0-255). on many systems, dereferencing a char vaalue causes an error, because low memory addresses are reserved for special purposes such as operating system interrupt handlers- so "memory violations" occur.


推荐答案

like:

char *pCh = 'A';  // this is the value 0x41 (assuming ASCII).
char Ch = *pCh;   // probably not what you wanted.

,因为字符和字符指针之间存在巨大差异。

because there is a vast difference between a character and a character pointer.

事实上,当你试图做这样的事情时,一个体面的编译器应该给你一个警告。

In fact, a decent compiler should give you a warning when you attempt to do something like that.

其余部分解释一种可能的效果。如果你在 char 值为8位的系统中工作,它们只能保存从0到255的值(ISO C标准允许char值更大,但相当不常见)。从该值集中随机选择的指针不太可能是有用的。

The rest of it explains one possible effect. If you're working in a system where char values are eight bits, they will only be able to hold values from 0 through 255 inclusive (the ISO C standard allows char values to be larger but it's fairly uncommon). It's very unlikely that a pointer chosen at random from that value set will be useful.

这不是完全在嵌入式系统上,你有内存映射I / O,但在这种情况下,你会更可能使用像 #define IOPORT7 0x0041 并使用 IOPORT7 而不是'A'

It's not totally out of the question since you may be on an embedded system where you have memory-mapped I/O down there but, in that case, you'd be more likely to use something like #define IOPORT7 0x0041 and use IOPORT7 rather than 'A'.

另一方面,往往能够指向你的整个地址空间,这可以是32位宽(或更大)。 32位可提供指针可指向的四个十亿个可能值。

Pointers, on the other hand, tend to be able to point at your entire address space, which can be 32 bits wide (or larger). 32 bits gives you about four billion possible values where a pointer can point to.

这篇关于这个关于char指针的引用是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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