Profetas <xuxu_18@yahoo. com> wrote:[color=blue]
> In a c program I have a var with the name of a file that I want to compile,
> how would I compile it using c code?[/color]
Probably by cobbling together a string with the command to invoke the
compiler, using your variable, and than feeding it to the system()
function.
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Profetas wrote:[color=blue]
> In a c program I have a var with the name of a file that I want to compile,
> how would I compile it using c code?[/color]
Of course, the actual invocation of your system's C compiler
might be more complicated than a mere "cc blivet.c". You may
need something like "cc -c blivet.c" or "cc -O3 -c -Iinc blivet.c"
or "cc /i:inc /optimize /noload blivet.c" -- it depends on the
platform you're using.
Even when you've constructed the desired command string,
your troubles are not over. The C Standard does not actually
promise that the system() function will do anything useful --
it usually does, but there's no guarantee. Also, system()
gives you no sure-fire way to check whether the compilation
succeeded or failed, or to examine any diagnostic messages
the compiler may have produced. In short, while the above
could be the skeleton of a solution, it isn't a very good
one. To get something more useful you'll probably need to
use platform-specific facilities.
>Probably by cobbling together a string with the command to invoke the[color=blue]
>compiler, using your variable, and than feeding it to the system()[/color]
function.
That worked Thanks I didn't know that the system accepted vars
Profetas wrote:[color=blue]
>
> In a c program I have a var with the name of a file that I want to compile,
> how would I compile it using c code?[/color]
The only possible way would be to invoke a separate compiler using the
system() function. The form of the command passed to the system is
completely platform dependent, if it can be done at all. It usually is
as if you were doing it yourself from the commandline.
Profetas wrote on 27/07/04 :[color=blue]
> In a c program I have a var with the name of a file that I want to compile,
> how would I compile it using c code?[/color]
You can call an external compiler via system(). s[n]printf() could help
to build the string to pass to system().
Profetas wrote on 27/07/04 :[color=blue][color=green]
>> Probably by cobbling together a string with the command to invoke the
>> compiler, using your variable, and than feeding it to the system()[/color]
> function.
>
> That worked Thanks I didn't know that the system accepted vars[/color]
The parameter of system() has the type 'char const *'. Hence, it
accepts any address pointing to a string. As far as the string is
valid, the behaviour is system dependent.
Comment