这是故意的吗? [英] is this intentional?

查看:87
本文介绍了这是故意的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

typedef struct foo * FOO;


struct foo {

int a;

};


void func(const FOO baz);


int main(无效)

{

struct foo baz;

func(& baz);

返回0;

}


void func(const FOO baz)

{

静态struct foo测试;

baz =& test;

返回;

}

这款对待baz作为const指针

到struct foo而不是指向struct foo的指针

由const限定。如果FOO真的是同义词

for struct foo,它就不会这样做。


标准的哪一部分描述了这种行为

如果我的编译器中没有错误?


-

aegis

typedef struct foo *FOO;

struct foo {
int a;
};

void func(const FOO baz);

int main(void)
{
struct foo baz;
func(&baz);
return 0;
}

void func(const FOO baz)
{
static struct foo test;
baz = &test;
return ;
}
this treats "baz" as a const pointer
to struct foo and not a pointer to struct foo
qualified by const. if FOO was really a synonym
for struct foo, it would not do this.

what part of the standard describes this behavior
if it isn''t a bug in my compiler?

--
aegis

推荐答案

aegis写道:

typedef struct foo * FOO;

struct foo {
int a;
};

void func(const FOO baz);

int main(void)
{
struct foo baz;
func(& baz);
返回0;
}

void func(const FOO baz)
{
静态结构foo测试;
baz =& test;
return;
}

这款对待baz作为const指针对结构foo而不是指向struct foo的指针
由const限定。如果FOO真的是struct foo的同义词,它就不会这样做。

typedef struct foo *FOO;

struct foo {
int a;
};

void func(const FOO baz);

int main(void)
{
struct foo baz;
func(&baz);
return 0;
}

void func(const FOO baz)
{
static struct foo test;
baz = &test;
return ;
}

this treats "baz" as a const pointer
to struct foo and not a pointer to struct foo
qualified by const. if FOO was really a synonym
for struct foo, it would not do this.




如果FOO真的是struct foo的同义词,

然后你的代码看起来像这样:

typedef struct foo FOO;

void func(const FOO * baz);


-

pete



If FOO was really a synonym for struct foo,
then your code would look like this:

typedef struct foo FOO;
void func(const FOO *baz);

--
pete




pete写道:

pete wrote:
aegis写道:

typedef struct foo * FOO;

struct foo {
int a;
};

void func(const FOO baz);

int main(无效)
{* / func boo;
func(& baz) ;
返回0;
}

void func(const FOO baz)
{
静态结构foo测试;
baz =&测试;
返回;


这对待baz作为const指针对结构foo而不是指向struct foo的指针
由const限定。如果FOO真的是struct foo的同义词,那就不会这样做。

typedef struct foo *FOO;

struct foo {
int a;
};

void func(const FOO baz);

int main(void)
{
struct foo baz;
func(&baz);
return 0;
}

void func(const FOO baz)
{
static struct foo test;
baz = &test;
return ;
}

this treats "baz" as a const pointer
to struct foo and not a pointer to struct foo
qualified by const. if FOO was really a synonym
for struct foo, it would not do this.



如果FOO真的是struct foo的同义词,
那你的代码就会看起来像这样:

typedef struct foo FOO;
void func(const FOO * baz);

-
pete



If FOO was really a synonym for struct foo,
then your code would look like this:

typedef struct foo FOO;
void func(const FOO *baz);

--
pete




我当然意味着


如果FOO真的是struct foo *的同义词,它就不会这样做

我的原始问题仍然存在。


-

aegis



I of course meant

"if FOO was really a synonym for struct foo *, it would not do this"
my original question remains.

--
aegis


2005年1月26日星期三00:11:12 -0800,aegis写道:
On Wed, 26 Jan 2005 00:11:12 -0800, aegis wrote:
typedef struct foo * FOO;

struct foo {
int a;
};

void func(const FOO baz);

int main(void)
结构foo baz;
func(& baz);
返回0;
}

void func(const FOO baz)

{静态struct foo test;
baz =& test;
return;
}

这款款待ba ž"作为const指针对结构foo而不是指向struct foo的指针
由const限定。


我没看到你想要的区别。如果FOO是一个指向

struct foo的指针,那么const FOO是一个指向struct foo的const指针。

如果FOO真的是同义词
对于struct foo,它不会这样做。


当您对指针类型进行限定时,您可以限定指针类型本身,而不是它所指向的类型
。我不清楚为什么你会这么想。

标准的哪一部分描述了这种行为,如果它不是我的编译器中的错误?
typedef struct foo *FOO;

struct foo {
int a;
};

void func(const FOO baz);

int main(void)
{
struct foo baz;
func(&baz);
return 0;
}

void func(const FOO baz)
{
static struct foo test;
baz = &test;
return ;
}
this treats "baz" as a const pointer
to struct foo and not a pointer to struct foo
qualified by const.
I don''t see the distinction you are trying to make. If FOO is a pointer to
struct foo then const FOO is a const pointer to struct foo.
if FOO was really a synonym
for struct foo, it would not do this.
When you qualify a pointer type you qualify the pointer type itself, not
the type it is pointing at. I''m not clear why you think otherwise.
what part of the standard describes this behavior if it isn''t a bug in
my compiler?




I C99 6.7.3描述了const。

劳伦斯



I C99 6.7.3 describes const.

Lawrence


这篇关于这是故意的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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