指针的结构,即还没有被宣布 [英] Pointer to a structure that has not been declared

查看:106
本文介绍了指针的结构,即还没有被宣布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  未定义的C结构正向声明

这怎么可能来声明一个指向结构,即使我不声明结构?

How is it possible to declare a pointer to structure even when I do not declare a structure?

#include<stdio.h>

int main(){
    struct s{
     struct p *ptr;
   }; 
}

为什么成功上面编译?

Why does the above compile successfully?

推荐答案

这是可能的,因为编译器不需要了解任何结构,如果只用一个指向它的交易。

It's possible because the compiler doesn't need to know anything about the structure if it only deals with a pointer to it.

这是一个常用的技术,通常被称为&ldquo;不透明的指针&rdquo;的。

This is a commonly used technique and is usually called an “opaque pointer”.

这篇关于指针的结构,即还没有被宣布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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