C中的指针:两个声明中的差异 [英] Pointers in C : Difference in the two declarations

查看:70
本文介绍了C中的指针:两个声明中的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下C语言中的声明是什么意思:

What do the following declarations in C mean :

char far *far *scr;
char far far** scr;

从我收集到的第一条语句来看,是一个指向类型为far的指针? 第二个是指向far类型的指针的指针?

From what I gather the first statement is a pointer of type pointer to far? And the second is a pointer to a pointer of type far ?

推荐答案

far不是C中的标准关键字,因此其确切含义和语义取决于编译器.通常,它适用于分段存储器体系结构,其中远"指针可以指向当前段的外部,而近"指针只能指向该段的内部.如今,如果您需要担心此类事情,那么您可能正在进行嵌入式开发.

far is not a standard keyword in C, so its exact meaning and semantics depend on the compiler. In general, it applies to segmented memory architectures where a "far" pointer can point outside the current segment, and a "near" pointer only within the segment. Nowadays you are probably doing embedded development if you need to worry about such things.

对于您的语法示例,far限定符的位置因编译器而异.一些编译器使用它与const类似(即,当它指向该指针时,它位于*的右侧),但是许多流行的编译器将其放在左侧,就好像它引用了数据一样.而不是指针.在您的示例中似乎是这种情况,它将使第一个(char far *far *)远指针指向远指针.但是,第二个(char far far**)将是指向远"指针的不合格(如果是默认值,则接近)指针.我个人不知道具有这种概念的编译器,并且会猜测另一个far是冗余的还是错误,但是,就像所说的,这是非标准的.也许某些编译器将巨大"指针实现为far far

As for your syntax examples, the placement of the far qualifier differs by compiler. Some compilers use it similarly to const (i.e., it goes on the right side of the * when it refers to that pointer), but many popular compilers place it on the left side instead, as though it referred to the data and not the pointer. This appears to be the case in your example, which would make the first (char far *far *) a far pointer to a far pointer. But second (char far far**) would then be a non-qualified (near, if that is the default) pointer to a "far far" pointer. Personally I'm not aware of a compiler that has such a concept, and would guess that the other far is either redundant or an error, but, like said, this is non-standard. Maybe some compiler implements a "huge" pointer as far far

这篇关于C中的指针:两个声明中的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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