void vs void *(哲学问题) [英] void vs void* (philosophical question)

查看:88
本文介绍了void vs void *(哲学问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据标准(ISO C99草案WG14 / N1124),void是无法完成的

不完整类型,包含空的

值。既然它声明了一个值的缺席可以被认为是一个

数据类型?


关于void *,它只是简单地重用相同的关键字(无效)或

他们有更密切的关系?我只想到一个 - 一个指针

到一个不完整的类型。但是,如果有人可以说虚空是一个值的价值,我们怎么能指向一个不存在
的东西呢?

-

一个人的自由停止在别人'开始的地方

Giannis Papadopoulos

计算机与通信工程部。 (CCED)

塞萨利大学
http:// dop .freegr.net /

According to the standard (ISO C99 draft WG14/N1124), void is the
incomplete type that cannot be completed and comprises the empty set of
values. Since it declares the absense of a value can it be considered a
data type?

Regarding void*, is it just a simple reuse of the same keyword (void) or
they have a closer relationship? I could think of only one - a pointer
to an incomplete type. However, if one could say that void is the
absense of a value, how can we have a pointer to something that does not
exist?
--
one''s freedom stops where others'' begin

Giannis Papadopoulos
Computer and Communications Engineering dept. (CCED)
University of Thessaly
http://dop.freegr.net/

推荐答案

Giannis Papadopoulos写道:
Giannis Papadopoulos wrote:
根据标准(ISO C99草案) WG14 / N1124),void是无法完成的
不完整类型,包含空的
值。既然它声明了某个值的缺失可以被认为是一种数据类型吗?

关于void *,它只是简单地重用相同的关键字(void)或
他们有更密切的关系?我只想到一个 - 指向不完整类型的指针。但是,如果有人可以说虚空是一个没有价值的东西,我们怎么能指向一个不存在的东西呢?
According to the standard (ISO C99 draft WG14/N1124), void is the
incomplete type that cannot be completed and comprises the empty set of
values. Since it declares the absense of a value can it be considered a
data type?

Regarding void*, is it just a simple reuse of the same keyword (void) or
they have a closer relationship? I could think of only one - a pointer
to an incomplete type. However, if one could say that void is the
absense of a value, how can we have a pointer to something that does not
exist?




这是'我最好的解释:


void *是指向(几乎)任何东西的指针。如果你取消引用

void *,你可能指的是32位整数或128位
浮点值。你可能指的是一个结构或一个
联盟。你可能指的是该死的__anything__。在C中,你做了簿记,而不是编译器(通常是)。


因为无效*可能指向任何东西,它是'最安全的

编译器将其视为特别指向__nothing的情况。你需要在使用之前将$ *
转换为另一种指针类型:


#include< stdio.h>


int main(无效)

{

int a = 42;

void * p =& a;

printf("%d \ n",*(int *)p);

返回0;

}


[mark @ icepick]



Here''s my best explanation:

A void * is a pointer to (just about) anything. If you dereference a
void *, you might be referring to a 32 bit integer or a 128 bit
floating point value. You might be referring to a structure or a
union. You might be referring to damn near __anything__. In C, you do
the bookkeeping, not the compiler (usually).

Since a void * may point to just about anything, it''s safest for the
compiler to treat it as if it points to __nothing in particular__. You
must convert a void * to another pointer type before using it:

#include <stdio.h>

int main(void)
{
int a = 42;
void *p = &a;
printf("%d\n", *(int *) p);
return 0;
}

[mark@icepick]


gcc -ansi -pedantic -Wall -O2 -o foo foo.c

[mark @ icepick]
gcc -ansi -pedantic -Wall -O2 -o foo foo.c
[mark@icepick]


./ foo

42

Mark F. Haigh
mf ***** @ sbcglobal.net

./foo
42
Mark F. Haigh
mf*****@sbcglobal.net


这篇关于void vs void *(哲学问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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