main

Non-standard signature of main() compiles successfully

自闭症网瘾萝莉.ら 提交于 2019-11-28 01:41:30
问题 In this code: int main(int a, int b) { printf(" main(int, int) works \n\n"); return 0; } the signature of main is main(int, int) , and it compiles successfully. Why? 回答1: Because the C standard doesn't prohibit non-standard signatures for main (see e.g. section 5.1.2 of the C99 standard). However, you'll find that if you compile under GCC with the -Wall flag, 1 it will complain: test.c:4: warning: second argument of 'main' should be 'char **' It assumes that you want to interact with a

int main(int argc, char *argv[])

此生再无相见时 提交于 2019-11-28 01:23:07
问题 If I have this: int main(int argc, char *argv[]) In the body, you can sometimes find programs using argv[1] . When do we use argv[1] over argv[0] ? Is it only when we just want to read the second argument in the command line? 回答1: By convention , argv[0] is the current program's name (or path), and argv[1] through argv[argc - 1] are the command-line arguments that the user provides. However, this doesn't have to be true -- programs can OS-specific functions to bypass this requirement, and

Why main method is marked as public?

China☆狼群 提交于 2019-11-27 23:18:05
I have a question that why main method is marked as public ? According to an answer on stackoverflow, It is declared as static "The method is static because otherwise there would be ambiguity: which constructor should be called?" But, can anyone can explain why it is declared public always? The initialization software that starts your program must be able to see main so that it can call it. Because the JLS, Section 12.1.4 , says so: The method main must be declared public, static, and void. It must specify a formal parameter (§8.4.1) whose declared type is array of String. If it's not public ,

Java - Can objects which are executing methods be garbage-collected?

◇◆丶佛笑我妖孽 提交于 2019-11-27 21:36:24
问题 In Java, I've done things like the following without thinking much about it: public class Main { public void run() { // ... } public static void main(String[] args) { new Main().run(); } } However, recently I've become unsure as to whether doing that is safe. After all, there is no reference to the Main object after it's created (well, there is the this reference, but does that count?), so it looks like there's a danger that the garbage collector might delete the object while it's in the

run main method using gradle “run” task

孤街浪徒 提交于 2019-11-27 21:34:35
问题 I want to run my main method via gradle task This is how I run via the cmd: java -cp RTMonitor.jar com.bla.MainRunner first_arg how should it be written in gradle? run { args += ['java -cp RTMonitor.jar com.bla.MainRunner first_arg'] } Update I have tried task myRun(type: JavaExec) { classpath configurations.main main = "com.bla.runners.StatsLogGenerator" args "arg1", "arg2" } and I got: Error:(71, 0) Could not find property 'main' on configuration container. the I have tried: task myRun(type

Running a python package [duplicate]

谁都会走 提交于 2019-11-27 20:54:15
问题 This question already has answers here : Execute an installed Python package as a script? (3 answers) Closed 4 years ago . Running Python 2.6.1 on OSX, will deploy to CentOS. Would like to have a package to be invoked from a command line like this: python [-m] tst For that, here is the directory structure made: $PYTHONPATH/ tst/ __init__.py # empty __main__.py # below dep.py # below The following is in the files: $ cat tst/__main__.py from .dep import DepClass print "Hello there" $ cat tst

Difference between main(void) and main() in C [duplicate]

↘锁芯ラ 提交于 2019-11-27 19:21:29
This question already has an answer here: What should main() return in C and C++? 17 answers Can anyone tell me the difference between int main() and int main(void) ? Why do both of them work and what is the default argument to int main() ? No difference under ordinary circumstances. This is no 'default argument to main()', since it has no arguments at all. Here's the un-ordinary circumstance. If you write your own call to main, then () will permit you to pass it any parameters you like, while (void) will force you to pass it none. Still, none of this matters in terms of the 99.99999999% case,

What's the use of the third, environment variable argument to the C++ main()?

情到浓时终转凉″ 提交于 2019-11-27 18:53:36
问题 I have come to understand that char **envp is the third argument to main , and with the help of the code below, I was able to see what it actually contains. int main(int argc, char *argv[], char *env[]) { int i; for (i=0 ; env[i] ; i++) std::cout << env[i] << std::endl; std::cout << std::endl; } My question is: why (in what situations) would programmers need to use this? I have found many explanations for what this argument does, but nothing that would tell me where this is typically used.

Why do we need argc while there is always a null at the end of argv?

走远了吗. 提交于 2019-11-27 18:38:35
It seems that the argv[argc] is always NULL , so I think we can traverse the argument list without argc . A single while loop will do this. If there is always a NULL at the end of argv , why do we need an argc ? Yes, argv[argc]==NULL is guaranteed. See C11 5.1.2.2.1 Program startup (my emphasis) If they are declared, the parameters to the main function shall obey the following constraints: The value of argc shall be nonnegative. argv[argc] shall be a null pointer. Providing argc therefore isn't vital but is still useful. Amongst other things, it allows for quick checking that the correct

What is the relation between the main() method and main thread in Java?

╄→гoц情女王★ 提交于 2019-11-27 18:33:46
My tutor told me that the main thread is the parent thread of every thread, but he is not able to explain why. When I write a simple program: Class A{} Then it at the time of execution it throws an exception: java.lang.NoSuchMethodError: main Exception in thread "main" Is there any relation between the main() method and the main thread? Is there any relation between main() method and Main Thread ? When the JVM starts, it creates a thread called "Main". Your program will run on this thread, unless you create additional threads yourself. The first thing the "Main" thread does is to look for your