存档

‘commenting’ 分类的存档

参照 Unix Programming Environment 来看NULL pointer

2003年12月12日 hufey 评论已被关闭

C FAQ
5.2: How do I get a null pointer in my programs?
… …
However, an argument being passed to a function is not
necessarily recognizable as a pointer context, and the compiler
may not be able to tell that an unadorned 0 “means” a null
pointer. To generate a null pointer in a function call context,
an explicit cast may be required, to force the 0 to be
recognized as a pointer. For example, the Unix system call
execl takes a variable-length, null-pointer-terminated list of
character pointer arguments, and is correctly called like this:
execl(”/bin/sh”, “sh”, “-c”, “date”, (char *)0);
If the (char *) cast on the last argument were omitted, the
compiler would not know to pass a null pointer, and would pass
an integer 0 instead. (Note that many Unix manuals get this
example wrong.)
… ….
《Unix 开发环境》第8章 8.9 小节
在使用ANSI C原型之前,对e x e c l , e x e c l e和e x e c l p三个函数表示命令行参数的一般方法是:
char * a rg 0, char *a rg 1, …, char * a rg n, (char *) 0
应当特别指出的是:在最后一个命令行参数之后跟了一个空指针。如果用常数0来表示一个空
指针,则必须将它强制转换为一个字符指针,否则它将被解释为整型参数。如果一个整型数的
长度与char *的长度不同,e x e c函数实际参数就将出错。

分类: commenting 标签:

还真有不是0的NULL,C语言的各种实现太乱了

2003年12月10日 hufey 2 条评论

5.17: 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 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.
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 the upper 16 bits to
indicate a byte address within a word.
References: K&R1 Sec. A14.4 p. 211.

分类: commenting 标签:

note of C FAQ

2003年12月8日 hufey 评论已被关闭

颠覆了我多年的观念
5.9: If NULL and 0 are equivalent as null pointer constants, which
should I use?
A: Many programmers believe that NULL should be used in all pointer
contexts, as a reminder that the value is to be thought of as a
pointer. Others feel that the confusion surrounding NULL and 0
is only compounded by hiding 0 behind a macro, and prefer to use
unadorned 0 instead. There is no one right answer. (See also
questions 9.2 and 17.10.) C programmers must understand that
NULL and 0 are interchangeable in pointer contexts, and that an
uncast 0 is perfectly acceptable. Any usage of NULL (as opposed
to 0) should be considered a gentle reminder that a pointer is
involved; programmers should not depend on it (either for their
own understanding or the compiler’s) for distinguishing pointer
0’s from integer 0’s.
NULL should *not* be used when another kind of 0 is required,
even though it might work, because doing so sends the wrong
stylistic message. (Furthermore, ANSI allows the definition of
NULL to be ((void *)0), which will not work at all in non-
pointer contexts.) In particular, do not use NULL when the
ASCII null character (NUL) is desired. Provide your own
definition
#define NUL ”
if you must.
References: K&R1 Sec. 5.4 pp. 97-8; K&R2 Sec. 5.4 p. 102.

分类: commenting 标签:

gcc compiler的问题

2003年11月20日 hufey 评论已被关闭

也许不应该算问题
具体还需要再查一下
这里计一下吧
classA的classB成员在A的Ctor中不会自动call classB的Ctor

分类: commenting 标签:

用电视看Mpeg4,够爽

2003年11月16日 hufey 评论已被关闭

中东高知的片子好是好,省了不少买碟的钱
可是在电脑上看毕竟不爽
也不方便全家人一起分享那
正好家里有一个笔记本一直闲置着
2000年买的ASUS,花了两万块,
PIII450还不带M的CPU
(那会没有带M的,第一块带M的就是500MHz了)
硬盘10G,内存192M已经是升级过,不能再升了
后来买了Desktop PC她在家里放着算是鸡肋
卖也卖不了多少钱,用着也不舒服
后来装上了Linux+Apache+MySql给媳妇写程序
做测试用
干脆再改造一下,现在成了一个mpeg4 player
其实也挺简单,过程如下:
装redhat 9,因为以前的版本不认板子上的AC97声卡
和lucent 瘟猫,装mplayer,找出一个音频线
一头接audio out,一头接功放aux audio in。
幸好电视本身有VGA input,否则还得显卡支持。
笔记本只要在bios里改成LCD和VGA both output就可以了
怎么样?效果还可以吧?
___________________________________________________
马上要做一个支持UPNP的DVD Player,将来就不用这么
麻烦了。未来(也许用不了两年),家里的电器都有一个
IP address,就不用这么麻烦啦

阅读全文…

分类: commenting 标签: