473,804 Members | 3,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How command line arguments are passed ?

Hi,

I have a very basic qus. An executable can be written using n number of
languages, viz C,,C++,Perl,Jav a,...And all these languages use different
calling convensions for example C uses cdecl and C++ uses fast call and so
on.
Now, my question how does the console window pass command line arguments to
the executable with out knowing whether it is a C or Java executable.

Thanking In Advance,
Subhransu Sahoo
Jul 23 '05 #1
7 1923
Subhransu Sekhar Sahoo wrote:

Hi,

I have a very basic qus. An executable can be written using n number of
languages, viz C,,C++,Perl,Jav a,...And all these languages use different
calling convensions for example C uses cdecl and C++ uses fast call and so
on.
Now, my question how does the console window pass command line arguments to
the executable with out knowing whether it is a C or Java executable.


It doesn't.
The 'console window' passes arguments in always the same way. The key
point is, that it doesn't pass those arguments to your main() (or the
equivalent in other languages) directly. Before main() runs other code
gets started, ( which eg. initializes global variables, sets up the
memory management etc. ) and this code knows about the way the
arguments from the console are passed and what main() expects.
--
Karl Heinz Buchegger
kb******@gascad .at
Jul 23 '05 #2
Sorry, I I don't understand how the code that you are refering to knows
about the calling convention that main() follows.
"Karl Heinz Buchegger" <kb******@gasca d.at> wrote in message
news:42******** *******@gascad. at...
Subhransu Sekhar Sahoo wrote:

Hi,

I have a very basic qus. An executable can be written using n number of
languages, viz C,,C++,Perl,Jav a,...And all these languages use different
calling convensions for example C uses cdecl and C++ uses fast call and so on.
Now, my question how does the console window pass command line arguments to the executable with out knowing whether it is a C or Java executable.


It doesn't.
The 'console window' passes arguments in always the same way. The key
point is, that it doesn't pass those arguments to your main() (or the
equivalent in other languages) directly. Before main() runs other code
gets started, ( which eg. initializes global variables, sets up the
memory management etc. ) and this code knows about the way the
arguments from the console are passed and what main() expects.
--
Karl Heinz Buchegger
kb******@gascad .at

Jul 23 '05 #3
Subhransu Sekhar Sahoo wrote:
Hi,

I have a very basic qus. An executable can be written using n number of
languages, viz C,,C++,Perl,Jav a,...And all these languages use different
calling convensions for example C uses cdecl and C++ uses fast call and so
on.
Now, my question how does the console window pass command line arguments to
the executable with out knowing whether it is a C or Java executable.

Thanking In Advance,
Subhransu Sahoo


executing a program does not mean calling main or whatever directly.
The whole thing is very plattform specific and each language has additionally
a wrapper around the main routine which adapts it to the runtime environment.
If you want to know more about this, you should read the documentation
for the linker (e.g. ld) of your development environment...

Tom
Jul 23 '05 #4
On Wed, 13 Jul 2005 11:36:16 GMT, Subhransu Sekhar Sahoo
<su************ @yahoo.com> wrote:
Sorry, I I don't understand how the code that you are refering to knows
about the calling convention that main() follows.
the code knows that because it is created by the very same linker
("executable maker") which also processes the code resulting from your
main and other source code.

imagine this: a linker (or linker/compiler pair) is both platform and
programming language dependent. the latter dependency constitues what
source code can be processed, and the former dependency constitutes on
which platform the produced executables can be run.

"Karl Heinz Buchegger" <kb******@gasca d.at> wrote in message
news:42******** *******@gascad. at...
Subhransu Sekhar Sahoo wrote:
>
> Hi,
>
> I have a very basic qus. An executable can be written using n number

of
> languages, viz C,,C++,Perl,Jav a,...And all these languages use

different
> calling convensions for example C uses cdecl and C++ uses fast call

and

so
> on.
> Now, my question how does the console window pass command line

arguments

to
> the executable with out knowing whether it is a C or Java executable.
>


It doesn't.
The 'console window' passes arguments in always the same way. The key
point is, that it doesn't pass those arguments to your main() (or the
equivalent in other languages) directly. Before main() runs other code
gets started, ( which eg. initializes global variables, sets up the
memory management etc. ) and this code knows about the way the
arguments from the console are passed and what main() expects.
--
Karl Heinz Buchegger
kb******@gascad .at



Jul 23 '05 #5
Subhransu Sekhar Sahoo wrote:

Sorry, I I don't understand how the code that you are refering to knows
about the calling convention that main() follows.


It knows it, because that code is part of your compiler system.
The very same guys that wrote your compiler also wrote that startup
code, so they know what to do with the passed arguments. The very
sam guys also know on which platform their compiler executes, so they
also know in which way the arguments are passed from the commmand line.

Just in case you haven't guessed it already: That startup code is part
of your executable. When the operating system starts your executable, that
startup code gets the control and gets the arguments passed.
The startup code reformats that arguments and in turn
calls main(), where you eventually get your hands at the arguments.
--
Karl Heinz Buchegger
kb******@gascad .at
Jul 23 '05 #6
This does actually not quite relate to the command line argument passing,
but rather about the runtime startup code. The question is does that piece
of startup code run ahead of or after the initialization of global objects
and static objects, or does the startup code actually calls those
constructors?

ben
Jul 23 '05 #7
benben wrote:

This does actually not quite relate to the command line argument passing,
but rather about the runtime startup code. The question is does that piece
of startup code run ahead of or after the initialization of global objects
and static objects, or does the startup code actually calls those
constructors?


I would say: the later.
The startup code collects all global objects and calls constructors as
necessary (some code has to call them). How this is done exactly is highly
implementation specifc.

But make a thought experiment: Assume you write a compiler. How would you
do it? You can do anything you want and are not bound by the C++ rules.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2782
by: Edvard Majakari | last post by:
Hi, I was wondering what would be the most elegant way for creating a Python class wrapper for a command line utility, which takes three types of arguments: 1. options with values (--foo=bar) 2. boolean options (--squibble) 3. data lines (MUNGE:x:y:z:frob)
7
2323
by: qazmlp | last post by:
void func() { // Is it by anyway possible to read the value of the first command line parameter i.e. argv here ? } int main() { func() ; // No command line arguments are passed to func(). }
7
2328
by: michael | last post by:
I have a question about Windows based python (2.4 and later). For example, if I make a script called test.py like so: import sys print sys.argv then run it: python test.py this is a test
7
4740
by: Steve M | last post by:
I'm trying to invoke a Java command-line program from my Python program on Windows XP. I cannot get the paths in one of the arguments to work right. The instructions for the program describe the following for the command-line arguments: java -jar sforcedataloader.jar -Dsalesforce.config.dir=CONFIG_DIRECTORY They also give an example:
6
2939
by: Edd Dawson | last post by:
Hi. I have a strange problem involving the passing of command line arguments to a C program I'm writing. I tried posting this in comp.programming yesterday but someone kindly suggested that I'd have better luck here. So here goes! My program ignores any command line arguments, or at least it's supposed to. However, when I pass any command line arguments to the program, the behaviour of one of the functions changes mysteriously. I have...
1
7905
by: amirmira | last post by:
I would like to set command line arguments to a service at install time. I need to do this because I need to get information from different registry locations depending on my command line argument. I have to do it this way as the consumer of the service should not be able to change the argument - except by uninstalling and reinstalling the service. I created the service and the service itself works great. However, when I try to install...
4
1991
by: Roland | last post by:
Hi, I am developing a C++ project and want to pass some command line arguments in VS .NET 2003. I am in debug mode, the configuration is set to Debug and I entered my argument list in Project -> Project Properties -> Configuration Properties -> Debugging -> Command Arguments. The blurb provided in the properties window for this field reads "The command line arguments to pass to the application." which sounded promising.
40
2756
by: raphfrk | last post by:
I have a program which reads in 3 filenames from the command line prog filename1 filename2 filename3 However, it doesn't work when one of the filenames has spaces in it (due to a directory name with a space in it) because that filename gets split into 2. I tried
17
3383
by: Matt | last post by:
Hello. I'm having a very strange problem that I would like ot check with you guys. Basically whenever I insert the following line into my programme to output the arguments being passed to the programme: printf("\nCommand line arguement %d: %s.", i , argv ); The porgramme outputs 3 of the command line arguements, then gives a segmentation fault on the next line, followed by other strange
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9588
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.