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

interesting and mysterious "argc" "argv"

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

Like Tree7Likes
  • 5 Post By wyldckat
  • 2 Post By bieshuxuhe

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 13, 2014, 11:24
Default interesting and mysterious "argc" "argv"
  #1
Member
 
xuhe-openfoam
Join Date: Aug 2013
Location: DaLian,china
Posts: 82
Rep Power: 12
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, 14:11
Default
  #2
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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
wyldckat is offline   Reply With Quote

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

Old   April 13, 2014, 23:26
Wink
  #4
Member
 
xuhe-openfoam
Join Date: Aug 2013
Location: DaLian,china
Posts: 82
Rep Power: 12
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
pfguo and fly_light like this.
bieshuxuhe is offline   Reply With Quote

Old   April 14, 2014, 03:42
Default
  #5
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21
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, 05:21
Default
  #6
Member
 
xuhe-openfoam
Join Date: Aug 2013
Location: DaLian,china
Posts: 82
Rep Power: 12
bieshuxuhe is on a distinguished road
thank you very much !
bieshuxuhe is offline   Reply With Quote

Reply

Tags
mysterious

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 11:33.