Is it possible to declare variables accessible only to a particular lib?
For exeample if i declare a variable in a library only the functions in that library should
have access to the variable.
Is that possible with DynamicC?
Dynamic C has a unique compiler that places almost everything into the global scope.
Variables declared between BeginHeader/EndHeader comments are visible outside of the library.
Variables declared after an EndHeader (with the code that’s linked into your firmware) are only visible to the code in that section. But note that code following the next EndHeader comment (or before the BeginHeader comment) cannot see it either.
But when I say visible, I just mean that other code won’t see the declaration. If another library or your main .C file try to declare variables with the same names, you’ll see compiler errors.
In Dynamic C 10, you can use the “Project Explorer” (from the Window menu) to add multiple .C files to your project. But they might share a single scope (I can’t recall, and don’t actually recommend using that feature).
Bottom line is that you should code your libraries with scoped variable/function/macro names (use a prefix, similar to the way “board_update.lib” uses “bu”) to avoid name conflicts. Prefix private variables/functions for a library with “_” and then avoid referencing them in other code outside of the library.