473,396 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Is there any point in ommitting arguments from main method definition?

static void Main(string[] args)
{
}

If you know your programme will not take any string arguments, would it
make any difference at all if you removed the string arguments from the
code? And had this instead: -

static void Main()
{
}

I've checked and it compiles, but both versions compile as the same
size.

So i'm curious why they are both the same size.

Does the compiler check to see if the string arguments are actually
used in the main method body? And if they are not it removes them from
the method signature prior to compilation?

Thanks,

Gary.

Dec 5 '06 #1
2 1095

ga********@myway.com wrote:
static void Main(string[] args)
{
}

If you know your programme will not take any string arguments, would it
make any difference at all if you removed the string arguments from the
code? And had this instead: -

static void Main()
{
}
No, it wouldn't affect the execution of your program.
I've checked and it compiles, but both versions compile as the same
size.

So i'm curious why they are both the same size.
I didn't spend the time reading the specification so this is just
guess. I tried it myself and found that both executables are 16384
bytes which is 2^14. This leads me to believe that the compiler
allocates space for the executable in chunks. Since we're talking
about such a small change to the program it's not enough to change the
number of chunks needed.
Does the compiler check to see if the string arguments are actually
used in the main method body? And if they are not it removes them from
the method signature prior to compilation?
No, it doesn't. You can verify this by running ildasm on both
executables.

Dec 5 '06 #2
Thankyou very much Brian.

I hadn't encountered ildasm before it looks very useful.

Gary.

Brian Gideon wrote:
ga********@myway.com wrote:
static void Main(string[] args)
{
}

If you know your programme will not take any string arguments, would it
make any difference at all if you removed the string arguments from the
code? And had this instead: -

static void Main()
{
}

No, it wouldn't affect the execution of your program.
I've checked and it compiles, but both versions compile as the same
size.

So i'm curious why they are both the same size.

I didn't spend the time reading the specification so this is just
guess. I tried it myself and found that both executables are 16384
bytes which is 2^14. This leads me to believe that the compiler
allocates space for the executable in chunks. Since we're talking
about such a small change to the program it's not enough to change the
number of chunks needed.
Does the compiler check to see if the string arguments are actually
used in the main method body? And if they are not it removes them from
the method signature prior to compilation?

No, it doesn't. You can verify this by running ildasm on both
executables.
Dec 5 '06 #3

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

Similar topics

9
by: Chuck Anderson | last post by:
I have a function with 7 inputs. The last three have default values. I want to call that function specifying the first four, skip two and then specify the last. I thought I could write this...
5
by: Gary Labowitz | last post by:
Is it permissable to place default arguments in the definition of a constructor rather than in the declaration. Following extract: class X { public: X(int arg1, int arg2); .... }
13
by: Laurent Schall | last post by:
I experience a problem where starting an application compiled with visual C++ 6 SP5 does not execute the function main(int argc, char **argv) and exit immediately with code 1 (0x1). Putting main...
5
by: Andy Buckley | last post by:
Hi, A friend and I have recently had trouble getting code to compile when using temporary objects in constructors. A minimal example is below: This code fragment is used to construct seven ROD...
6
by: aneesh | last post by:
Hi all, I would like to know whether we can specify another function instead of main as entry point. Thanks Aneesh
4
by: Augustus S.F.X Van Dusen | last post by:
I have recently come across the following construction: #define P_VAR(output, string, args...) \ fprintf (output, "This is "string"\n", ##args) which can be invoked as follows: int x = 1,...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
3
by: noro | last post by:
Hi all, I use a method that accept multiply arguments ("plot(*args)"). so plot() is accepted and plot(,) is also accepted. the problem is that i know the number of arguments only at runtime....
10
by: Janus | last post by:
Hi, Is there a way to pass arguments to the callback function used inside an addEventListener? I see that I can only list the name of the callback function. For eg, I use this: var...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.