8

Possible Duplicate:
undefined C struct forward declaration

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?

Community
  • 1
  • 1
Bazooka
  • 1,428
  • 4
  • 15
  • 24

2 Answers2

10

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

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

dreamlax
  • 93,976
  • 29
  • 161
  • 209
0

Look into the below link

http://cboard.cprogramming.com/cplusplus-programming/100298-opaque-pointer.html

Rasmi Ranjan Nayak
  • 11,510
  • 29
  • 82
  • 122