取消引用指针不完全类型 [英] dereferencing pointer to incomplete type

查看:138
本文介绍了取消引用指针不完全类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了很多关于这个问题,但我会以不同的方式问的问题没有具体的code。有没有一种方法 轻轻松松确定是什么原因造成的类型是不完整?就我而言,我用别人的code和我完全相信我没有正确的标题,但(因为电脑做这个东西更快,比人的眼球越好)有没有办法让编译器说:嘿,你的认为的你在第34行的X型,但是这实际上丢失的。错误本身只出现在你指定,这是不是非常有帮助。

I've seen a lot of questions on this but I'm going to ask the question differently without specific code. Is there a way of EASILY determining what is causing the type to be incomplete? In my case I'm using someone elses code and I'm completely sure I don't have the headers right, but (since computers do this stuff much faster and better than human eyeballs) is there a way to get the compiler to say, "hey you think you have type X at line 34 but that's actually missing." The error itself only shows up when you assign, which isn't very helpful.

推荐答案

我看到了一个问题,那天如果有人无意中通过指定类似结构A {INT●用于一个不完整的类型; };结构A * X; X-GT&Q = 3; 。编译器知道结构A 是一个结构,尽管 A 是完全不确定的,凭借<$ C $的C>结构关键字。

I saw a question the other day where someone inadvertently used an incomplete type by specifying something like struct a { int q; }; struct A *x; x->q = 3;. The compiler knew that struct A was a struct, despite A being totally undefined, by virtue of the struct keyword.

这是在C ++中,其中结构的这种用法是非典型的(而且,事实证明,可能导致脚拍摄)。在C语言中,如果你做

That was in C++, where such usage of struct is atypical (and, it turns out, can lead to foot-shooting). In C if you do

typedef struct a {
    ...
} a;

那么你可以使用 A 作为类型名称和省略结构之后。这将导致编译器以后给你一个未定义的标识符错误,而不是不完全类型,如果你输错名称或忘记了一个头。

then you can use a as the typename and omit the struct later. This will lead the compiler to give you an undefined identifier error later, rather than incomplete type, if you mistype the name or forget a header.

这篇关于取消引用指针不完全类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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