Skip to content

Potential chapter 2 compile errors FIXES #55

@F-Kearney

Description

@F-Kearney

Just a few things that tripped me up while following along:

The functions ht_new and ht_del_hash_table are used in main.c but aren’t declared in hash_table.h. This causes an “implicit declaration” compiler error. Adding the declarations to the header file fixes it:

ht_hash_table* ht_new(void);
void ht_del_hash_table(ht_hash_table* ht);

The code uses strdup, which isn’t part of the C standard library by default — it’s POSIX. On some systems (like when compiling with gcc -Wall -Wextra -std=c99), you’ll get an “incompatible integer to pointer conversion” error unless you define the right macro. Adding this flag fixes it:

-D_POSIX_C_SOURCE=200809L

Might be worth adding a note that you need to compile both main.c and hash_table.c, like:

gcc -g -Wall -Wextra -D_POSIX_C_SOURCE=200809L main.c hash_table.c -o program

Hope this helps others avoid the same confusion. Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions