CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   interesting and mysterious "argc" "argv" (http://www.cfd-online.com/Forums/openfoam-programming-development/133309-interesting-mysterious-argc-argv.html)

bieshuxuhe April 13, 2014 10:24

interesting and mysterious "argc" "argv"
 
hi !
we often see the code :
Code:

int main(int argc, char *argv[])
I know that
argc is an integer showing the number of parameters that your program was called with.
argv is an array of strings (double pointer of chars) containing the actual parameters.

but I want to know where the declaration of variables "int argc, char *argv[]" are in source code ?:confused:
I want to have a look at them:)

could you help me?

wyldckat April 13, 2014 13:11

Quick answer:
  1. It's part of the C/C++ standard: http://en.wikipedia.org/wiki/Entry_point - therefore, "main" function simply must exist for an application to work.
  2. If you're looking for "args" as OpenFOAM reinterprets them, then look for "args" here: http://foam.sourceforge.net/docs/cpp/
  3. Good example: applications/utilities/mesh/manipulation/checkMesh/checkMesh.C

bieshuxuhe April 13, 2014 21:14

thank you ! I will careful read them .

bieshuxuhe April 13, 2014 22:26

Quote:

Originally Posted by wyldckat (Post 485830)
Quick answer:
  1. It's part of the C/C++ standard: http://en.wikipedia.org/wiki/Entry_point - therefore, "main" function simply must exist for an application to work.
  2. If you're looking for "args" as OpenFOAM reinterprets them, then look for "args" here: http://foam.sourceforge.net/docs/cpp/
  3. Good example: applications/utilities/mesh/manipulation/checkMesh/checkMesh.C

dear !
I have saw the code :
Code:

00001 //
00002 // setRootCase.H
00003 // ~~~~~~~~~~~~~
00004
00005    Foam::argList args(argc, argv);
00006    if (!args.checkRootCase())
00007    {
00008        Foam::FatalError.exit();
00009    }

I know from the code that "args" is a object of the argList class !:)
And when we use the variables "argc, argv" to construct the object "args" , we must declare "argc, argv" in advance !;) Then I wonder where are they declared ?:confused:
thanks!

xuhe

Bernhard April 14, 2014 02:42

That is some default C(++) behavior.
See for example http://stackoverflow.com/questions/3...char-argv-mean

bieshuxuhe April 14, 2014 04:21

thank you very much !


All times are GMT -4. The time now is 01:36.