Argv and Argc

Hallo guys I'm having some trouble with a question. The question goes like this: g++ -S fred.c >fred.asm is entered into the command line in windows using the gcc compiler.

What will the values of the arguments be passed to the g++ main function?

What will happen to the file fred.asm?

If g++ succeeds in generating the assembler file what will the value of main return function be?

My guess is that argc will be 4 and argv will be g++ -S fred.c. I am unsure if >fred.asm will be included in argv?

That is the question but I am wondering how do I capture the arguments argc and argv from the command line?

Since I am new to this forum, is this forum only for c++ or is just c also allowed?

Any help appreciated.
Last edited on
But you can easily test it yourself. Write dummy program (and call its executable "g++" if you like) and make it print out argv and argc. :)

I think ">fred.asm" would not be included as any redirection. Program is supposed to work identically independent of whether its output would be redirected or not.

It looks like the pure C is all right at this forum.
closed account (o3hC5Di1)
Hi there,

Blindesambok wrote:
Since I am new to this forum, is this forum only for c++ or is just c also allowed?


As C is a subset of C++, C questions are allowed, but you will usually get replies which include and promote C++ examples and explanations.

As for the question (if I understand it correctly): First '>' is a command redirection operator within the windows command shell - it will thus not be passed to g++, but rather the output produced by g++ will be sent to the file fred.asm.

There are only two arguments to g++:

-S = Only compile the source files, do not assemble (or link) them.
fred.c = your source file

For more information:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true
http://gcc.gnu.org/onlinedocs/gcc-3.0/gcc_3.html#SEC5

On a sidenote: I'm not sure that line would work, the documentation does not state that g++ -S sends its output to stdout, but rather that it creates a new file.

Hope that helps, please do let us know if you have any further questions.

All the best,
NwN
Topic archived. No new replies allowed.