0

I am getting strange compilation errors from trying to create a struct in C.

Here is my code:

#define ALIGNMENT 8

/* rounds up to the nearest multiple of ALIGNMENT */
#define ALIGN(size) (((size) + (ALIGNMENT-1)) & ~0x7)

#define SIZE_T_SIZE (ALIGN(sizeof(size_t)))

#define BLK_HDR_SIZE ALIGN(sizeof(blockHdr))


typdef struct header {
    size_t size;
    blockHdr *next_p;
    blockHdr *prior_p;
} blockHdr;

This is the error message:

 mm.c:49:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘struct’
 typdef struct header {
        ^
make: *** [mm.o] Error 1

I am baffled by this error. Is there something wrong with my code, or is there a more serious issue?

4
  • Look at the order of your typedef declaration and your variable declaration. You also have a typo in typdef Commented Nov 14, 2014 at 5:22
  • typdef? Is it a typo in this question or in your original code? Commented Nov 14, 2014 at 5:23
  • @YuHao Wow I made a dumb mistake. Commented Nov 14, 2014 at 5:24
  • I sat there and stared at this for half an hour and dug into various places. Commented Nov 14, 2014 at 5:24

2 Answers 2

3

You have a typo in typdef. Next, you'll get an error about blockHdr not being defined.

The correct definition is:

typedef struct header {
    size_t size;
    struct header *next_p;
    struct header *prior_p;
} blockHdr;

You can't use the typedef before it is declared. You have to use the actual structure name.

Sign up to request clarification or add additional context in comments.

Comments

1

I think that that instead of

typdef struct header

it should be

typedef struct header

1 Comment

He's going to have another problem after that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.