1
typedef struct 
{ 
WORD bfType; 
DWORD bfSize; 
WORD bfReserved1; 
WORD bfReserved2; 
DWORD bfOffBits; 
} __attribute__((__packed__)) 
BITMAPFILEHEADER; 

And then in the resize.c:

BITMAPFILEHEADER bf
fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);

I want to know some reference to run

BITMAPFILEHEADER bf

get a shorthand for BITMAPFILEHEADER?

I only know

typedef <oldname> <newname>  

How comes, just works?

Thanks in advance for any help of clarifying this point for me.

4

I'm assuming that you are asking why the typedef in bmp.h works. If not, please clarify your question, and I'll update the answer.

In bmp.h:

typedef struct 
{ 
    WORD bfType; 
    DWORD bfSize; 
    WORD bfReserved1; 
    WORD bfReserved2; 
    DWORD bfOffBits; 
} __attribute__((__packed__)) 
BITMAPFILEHEADER;

is really the same thing as a statement:

typedef <oldname> <newname>;

In this particular case, <oldname> is actually all of the following:

struct 
    { 
        WORD bfType; 
        DWORD bfSize; 
        WORD bfReserved1; 
        WORD bfReserved2; 
        DWORD bfOffBits; 
    } __attribute__((__packed__)) 

which is an anonymous structure. The full statement takes this unnamed structure and makes an alias for it (BITMAPFILEHEADER).

Now you can use BITMAPFILEHEADER as a type like int or double. The declaration BITMAPFILEHEADER bf reserves enough memory for a local variable to store that entire structure.

| improve this answer | |
  • Now, I understand. Thanks a lot. – juanli Sep 28 '17 at 17:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .