Mail Archives: djgpp-workers/1996/08/01/07:01:05
There are cases when it is convenient to get some code run before `main'
is called. A case in point is GNU Textutils and Fileutils, where some
programs need to switch their standard streams to O_BINARY, or convert all
command-line filenames to Unix forward-slash form. In some cases there is
an alternative solution (put the code inside `main'). In other cases, the
DJGPP-specific code gets scattered across the entire source whereas it
could be put only in a single function if it would run before `main'. In
any case, it is ugly and clutters the original sources, making it harder
to convince the maintainers to include the DJGPP-specific changes.
Currently, the only other way is to provide custom crt1 functions, but
they will need to duplicate most (if not all) of the code of existing
functions. I think it is a good idea to add a call to a user-definable
function just before `main' is called. The library will include an empty
version of this function, but a user can define their customized version
which will then be linked in instead of the default.
Comments? Is one such function enough, or is there need for several
(say, before and after the command-line arguments are expanded)?
- Raw text -