You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When libraries are #include-ed in header, in this context, mpc.h, it pollutes the namespace.
After reading a few articles and posts on online boards, I've been informed that such libraries should be part of mpc.c, and mpc.h should contain the bare minimum.
Since these headers have a header guard, the compiler does not complain while building, and this behavior goes unnoticed.
To explain the situation in more detail, I have a separate branch that uses GNU Autotools to build the library dynamically. Now, when I try to follow the Build Your Own Lisp tutorial, the library build just fine without including libraries like stdio, stdlib and string.
This is a unpredictable behavior, the context might be lost, and in a way, this #include goes beyond the scope of the source file (that is, mpc.c) it was supposed to be contained to, all the way to our source code, and potentially even other headers, if included to introduce type definitions.
As a reference, ediltine takes it to the next step by providing a public and private header, which in my opinion, can be used to isolate type definitions, and essential public functions from private functions needed for the internal working of said public function for abstraction.
What do you think of it?
The text was updated successfully, but these errors were encountered:
Well I agree there are probably some standard library includes in mpc.h which can be moved to mpc.c. Feel free to make a pull request moving those. However some probably need to be left in the header since there are function declarations which depend on them (e.g. <stdio.h> is probably required because of the use of FILE).
When libraries are
#include
-ed in header, in this context,mpc.h
, it pollutes the namespace.After reading a few articles and posts on online boards, I've been informed that such libraries should be part of
mpc.c
, andmpc.h
should contain the bare minimum.Since these headers have a header guard, the compiler does not complain while building, and this behavior goes unnoticed.
To explain the situation in more detail, I have a separate branch that uses GNU Autotools to build the library dynamically. Now, when I try to follow the Build Your Own Lisp tutorial, the library build just fine without including libraries like
stdio
,stdlib
andstring
.How the actual code should look like:
prompt.c
How it is currently, because of namespace pollution:
prompt.c
This is a unpredictable behavior, the context might be lost, and in a way, this
#include
goes beyond the scope of the source file (that is,mpc.c
) it was supposed to be contained to, all the way to our source code, and potentially even other headers, if included to introduce type definitions.As a reference, ediltine takes it to the next step by providing a public and private header, which in my opinion, can be used to isolate type definitions, and essential public functions from private functions needed for the internal working of said public function for abstraction.
What do you think of it?
The text was updated successfully, but these errors were encountered: