0

Speller pset: I am working on building a trie for the dictionary (load). In order to do so, I know I need to create the struct node. I thought that this was supposed to go in the dictionary.h file because it is a global definition. However, in my research, all the examples I see are in the dictionary.c file. Why is that?

Many thanks

1

I'd say dictionary.c, because speller.c, which includes dictionary.h does not need to know any details of your implementation (this also reduces chances of a name conflict). Based on the header file, it knows the signatures of the functions like load and check, and that's all it must know.

This goes for the node type definition, and especially any variables. Keep private what does not need to be public, as there are no namespaces in C, and you'd clutter the only namespace you have.

1
  • And small side note: Since #include works like replacing the line with the content of that file, a variable definition in a header file creates a different variable of the same name in all the files #including the header, unless you use the extern keyword, which creates a binding but no actual variable, to be resolved by the linker, but that's a thing for later.
    – Blauelf
    Jan 2 '19 at 22:59

You must log in to answer this question.

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