0

What are the benefits of this? The structure is declared in the header file, and is defined in the original file as follows:

a.h

struct A;  //declared in the header
struct B{
    struct A *a;
    int b;
    int c;
};

a.c

//defined in the original file
struct A{
    int c;
    int d;
};
Support Ukraine
  • 42,271
  • 4
  • 38
  • 63
newlinuxer
  • 23
  • 2
  • 1
    The member `a` in `struct B` is an [opaque pointer](https://en.wikipedia.org/wiki/Opaque_pointer). The `struct A` itself is an [opaque data type](https://en.wikipedia.org/wiki/Opaque_data_type) when seen from `"a.h"` or files that `#include "a.h"`. – pmg Jul 19 '21 at 08:22
  • 2
    The purpose it to not reveal internal details of the struct to any client using the header. – Gerhardh Jul 19 '21 at 08:24
  • to Gerhardh: your answer does make sense, any other benefits? – newlinuxer Jul 19 '21 at 08:30
  • to pmg : THANKS!!!! I've never known the word to describe this. NOW I now its called opaque pointer. the word in wikipedia helps me a lot – newlinuxer Jul 19 '21 at 08:33
  • You can also use it in case you have 2 structs that contain pointers to each other. You must use an opaque pointer in one of them to break the circular dependency. – Gerhardh Jul 19 '21 at 10:41

0 Answers0