C typedef underscore aliases in declaration

71 Views Asked by At

pdfium's public headers often contain constructs like this

typedef enum _FPDF_DUPLEXTYPE_ {
  DuplexUndefined = 0,
  Simplex,
  DuplexFlipShortEdge,
  DuplexFlipLongEdge
} FPDF_DUPLEXTYPE;

typedef struct _FS_MATRIX_ {
  float a;
  float b;
  float c;
  float d;
  float e;
  float f;
} FS_MATRIX;

typedef struct FPDF_BSTR_ {
  char* str;
  int len;
} FPDF_BSTR;

Contrast this to, e.g.

typedef enum {
  FPDF_RENDERERTYPE_AGG = 0,
  FPDF_RENDERERTYPE_SKIA = 1,
} FPDF_RENDERER_TYPE;

where the underscore alias is omitted.

What's the point of the underscore aliases, like _FPDF_DUPLEXTYPE_ ? (Note: I'm not a C developer, just reading the headers and trying to understand why this is done.)

1

There are 1 best solutions below

5
0___________ On
  1. Identifiers in C atrting with _ are reserved and must not e used.
  2. They are not alisses but tags.
  3. ALL CAPITAL IDENTIFIES USUALY ARE USED IN MACRODEFINITIONS
  4. Tags are used in struct declarations or in forward declarations.

Example:

typedef struct SomeStruct {
  float a;
  float b;
  float c;
  float d;
  float e;
  float f;
  struct FS_MATRIX *next;
} SomeStruct;


typedef enum enum1 enum1;

typedef struct struct1 struct1;

struct struct1
{
    enum1 *e1;
    struct1 *s1;
};