J
James Harris
Up to now I have usually written C modules as stand alone programs and
stored them in separate directories. This has been OK but is
inflexible, making interaction between them and having multiple
generations of a given piece of code awkward. Have you guys any
suggestions on how to organise C source code for use when developing
small to medium size projects?
This may be a generic query and maybe you use a certain tried and
tested scheme for every C program you write but if it helps to explain
the context it is as follows.
I would like to adopt a scheme that I can use for all C code from now
on. The model I have in mind is to have some apps (by which I mean
things such as user-facing programs) and some utilities. The utils
should be usable by multiple apps. At some point it may even be useful
for the apps to call each other. That is not a current requirement,
only a query in my mind as to whether there is some reason that apps
and utilities need to be distinguished.
Different generations of a given app or utility may need to be
available at the same time. In other words, I may need to keep a
certain piece of code around even though there is a newer version of
the same code.
At some point - might as well be now - I think I will need to use some
source code management application: GIT, Bazaar, Subversion or
similar. I might use it initially for local working but later to allow
collaboration. I guess that the choice of SCM affects how source code
is laid out. For example, it would be simpler to manage all files in a
given folder rather than selected ones.
I would like to be able to treat each app or util as an entity and
move or copy it around without having to also copy anything other than
the utils it depends on.
Ideally, compilation would treat the source code directories as read-
only and generate all of its output in a place relevant to the target
architecture; I would like to be able to build the same code for
different operating systems.
The above leads to questions over how best to include headers from
other directories and how to specify what to link together. I would
like to avoid use of environment variables as far as possible. Builds
should take the latest versions of a utility by default and only
choose older ones if told explicitly to do so. Makefiles are great if
building under Unix and I would prefer to use them to specify where
referenced files sit. Not sure what I would use if building under
Windows which I might have to do in some cases.
Sorry that's a long list. Hopefully it is a fairly standard set of
requirements!
James
stored them in separate directories. This has been OK but is
inflexible, making interaction between them and having multiple
generations of a given piece of code awkward. Have you guys any
suggestions on how to organise C source code for use when developing
small to medium size projects?
This may be a generic query and maybe you use a certain tried and
tested scheme for every C program you write but if it helps to explain
the context it is as follows.
I would like to adopt a scheme that I can use for all C code from now
on. The model I have in mind is to have some apps (by which I mean
things such as user-facing programs) and some utilities. The utils
should be usable by multiple apps. At some point it may even be useful
for the apps to call each other. That is not a current requirement,
only a query in my mind as to whether there is some reason that apps
and utilities need to be distinguished.
Different generations of a given app or utility may need to be
available at the same time. In other words, I may need to keep a
certain piece of code around even though there is a newer version of
the same code.
At some point - might as well be now - I think I will need to use some
source code management application: GIT, Bazaar, Subversion or
similar. I might use it initially for local working but later to allow
collaboration. I guess that the choice of SCM affects how source code
is laid out. For example, it would be simpler to manage all files in a
given folder rather than selected ones.
I would like to be able to treat each app or util as an entity and
move or copy it around without having to also copy anything other than
the utils it depends on.
Ideally, compilation would treat the source code directories as read-
only and generate all of its output in a place relevant to the target
architecture; I would like to be able to build the same code for
different operating systems.
The above leads to questions over how best to include headers from
other directories and how to specify what to link together. I would
like to avoid use of environment variables as far as possible. Builds
should take the latest versions of a utility by default and only
choose older ones if told explicitly to do so. Makefiles are great if
building under Unix and I would prefer to use them to specify where
referenced files sit. Not sure what I would use if building under
Windows which I might have to do in some cases.
Sorry that's a long list. Hopefully it is a fairly standard set of
requirements!
James