如果是NULL宏不为0? [英] When was the NULL macro not 0?

查看:181
本文介绍了如果是NULL宏不为0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我依稀记得几年前阅读有关这一点,但我不能在网络上找到任何引用。

您能给我一个示例,其中空宏并没有扩大到0?

编辑为清楚:今天,它扩展为((无效*)0)(0),或(0L)。然而,有架构早已被人遗忘的地方,这是不正确的,NULL扩展到不同的地址。类似

  #IFDEF UNIVAC
     的#define NULL(0xFFFF的)
#万一

我在寻找这样一台机器的一个例子。

更新来解决这些问题:

我并不是在现行标准的背景下,这个问题,或者得罪人与我的不正确的术语。然而,我的假设被接受的答案证实:

使用[等等],显然是为了安慰所有现存的不良-编写的C code这让不正确的假设以后的机型。

有关空指针在现行标准的讨论,请参阅this问题


解决方案

的C常见问题与非0空RE presentations历史的机器的一些例子。

的C常见问题列表,的问题5.17


  

问:说真的,真的使用任何实际的机器非零空
  指针,或者指向不同的不同的再presentations
  类型?


  
  

答:总理50系列用段07777,对于零偏移0
  指针,为PL / I最少。使用段0之后的机型,偏移0
  用C空指针,因此需要新的指令,例如TCNP(测试
  C语言的零指针),显然是为了安慰[脚注]所有现存的
  写得不好的C $ C $ç这让不正确的假设。年纪大了,
  字寻址总理机器也是臭名昭著的需要更大
  字节指针(字符*的)余万字的指针(INT *的)。


  
  

从数据一般Eclipse的MV系列有三个建筑
  支承指针格式(字,字节和位指针),其中两个
  正在使用的C编译器:字节指针的char *和void *的,和字
  指针一切。为了在历史的原因
  从16位诺瓦线,字的32位中压线的进化
  指针和字节指针有偏移,间接,和环
  在字不同的地方保护位。传递不匹配
  指针格式功能导致保护错误。
  最终,MV C编译器添加了许多兼容性选项尝试
  处理code,它有指针类型不匹配错误。


  
  

有些霍尼韦尔牛市大型机使用的位模式为06000
  (内部)空指针。


  
  

疾病预防控制中心网络180系列拥有包括环的48位指针,
  段,和偏移量。多数用户(在环11)具有空指针
  0xB00000000000。这是常见的旧CDC那些补机
  使用全1位字作为一个特殊的标志各种数据,
  包括无效的地址。


  
  

旧的HP 3000系列采用了字节不同的寻址方案
  地址比字地址;像数以上的机器
  因此,使用不同的重新presentations对于char *和*无效
  指针比其他指针。


  
  

在对符号Lisp机器,带标签的架构,甚至没有
  传统的数字指针;它使用了一对(基本上是
  不存在的句柄)为C空指针。


  
  

根据所使用的``内存模型',8086系列处理器(PC
  兼容机)可以使用16位的数据指针和32位功能
  指针,反之亦然。


  
  

一些64位的Cray机器重新present为int *中的低48位
  字;字符*另外使用了一些的高16位的指示
  一个字内的字节地址。


I vaguely remember reading about this a couple of years ago, but I can't find any reference on the net.

Can you give me an example where the NULL macro didn't expand to 0?

Edit for clarity: Today it expands to either ((void *)0), (0), or (0L). However, there were architectures long forgotten where this wasn't true, and NULL expanded to a different address. Something like

#ifdef UNIVAC
     #define NULL (0xffff)
#endif

I'm looking for an example of such a machine.

Update to address the issues:

I didn't mean this question in the context of current standards, or to upset people with my incorrect terminology. However, my assumptions were confirmed by the accepted answer:

Later models used [blah], evidently as a sop to all the extant poorly-written C code which made incorrect assumptions.

For a discussion about null pointers in the current standard, see this question.

解决方案

The C FAQ has some examples of historical machines with non-0 NULL representations.

From The C FAQ List, question 5.17:

Q: Seriously, have any actual machines really used nonzero null pointers, or different representations for pointers to different types?

A: The Prime 50 series used segment 07777, offset 0 for the null pointer, at least for PL/I. Later models used segment 0, offset 0 for null pointers in C, necessitating new instructions such as TCNP (Test C Null Pointer), evidently as a sop to [footnote] all the extant poorly-written C code which made incorrect assumptions. Older, word-addressed Prime machines were also notorious for requiring larger byte pointers (char *'s) than word pointers (int *'s).

The Eclipse MV series from Data General has three architecturally supported pointer formats (word, byte, and bit pointers), two of which are used by C compilers: byte pointers for char * and void *, and word pointers for everything else. For historical reasons during the evolution of the 32-bit MV line from the 16-bit Nova line, word pointers and byte pointers had the offset, indirection, and ring protection bits in different places in the word. Passing a mismatched pointer format to a function resulted in protection faults. Eventually, the MV C compiler added many compatibility options to try to deal with code that had pointer type mismatch errors.

Some Honeywell-Bull mainframes use the bit pattern 06000 for (internal) null pointers.

The CDC Cyber 180 Series has 48-bit pointers consisting of a ring, segment, and offset. Most users (in ring 11) have null pointers of 0xB00000000000. It was common on old CDC ones-complement machines to use an all-one-bits word as a special flag for all kinds of data, including invalid addresses.

The old HP 3000 series uses a different addressing scheme for byte addresses than for word addresses; like several of the machines above it therefore uses different representations for char * and void * pointers than for other pointers.

The Symbolics Lisp Machine, a tagged architecture, does not even have conventional numeric pointers; it uses the pair (basically a nonexistent handle) as a C null pointer.

Depending on the ``memory model'' in use, 8086-family processors (PC compatibles) may use 16-bit data pointers and 32-bit function pointers, or vice versa.

Some 64-bit Cray machines represent int * in the lower 48 bits of a word; char * additionally uses some of the upper 16 bits to indicate a byte address within a word.

这篇关于如果是NULL宏不为0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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