CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

interesting and mysterious "argc" "argv"

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 2 Post By wyldckat

Reply
 
LinkBack Thread Tools Display Modes
Old   April 13, 2014, 10:24
Default interesting and mysterious "argc" "argv"
  #1
Member
 
xuhe-openfoam
Join Date: Aug 2013
Location: DaLian,china
Posts: 82
Rep Power: 4
bieshuxuhe is on a distinguished road
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 ?
I want to have a look at them

could you help me?
bieshuxuhe is offline   Reply With Quote

Old   April 13, 2014, 13:11
Default
  #2
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,516
Blog Entries: 34
Rep Power: 86
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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
hua1015 and soheil_r7 like this.
wyldckat is offline   Reply With Quote

Old   April 13, 2014, 21:14
Default
  #3
Member
 
xuhe-openfoam
Join Date: Aug 2013
Location: DaLian,china
Posts: 82
Rep Power: 4
bieshuxuhe is on a distinguished road
thank you ! I will careful read them .
bieshuxuhe is offline   Reply With Quote

Old   April 13, 2014, 22:26
Wink
  #4
Member
 
xuhe-openfoam
Join Date: Aug 2013
Location: DaLian,china
Posts: 82
Rep Power: 4
bieshuxuhe is on a distinguished road
Quote:
Originally Posted by wyldckat View Post
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 ?
thanks!

xuhe
bieshuxuhe is offline   Reply With Quote

Old   April 14, 2014, 02:42
Default
  #5
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 12
Bernhard is on a distinguished road
That is some default C(++) behavior.
See for example http://stackoverflow.com/questions/3...char-argv-mean
Bernhard is offline   Reply With Quote

Old   April 14, 2014, 04:21
Default
  #6
Member
 
xuhe-openfoam
Join Date: Aug 2013
Location: DaLian,china
Posts: 82
Rep Power: 4
bieshuxuhe is on a distinguished road
thank you very much !
bieshuxuhe is offline   Reply With Quote

Reply

Tags
mysterious

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 19:27.