run main method using gradle “run” task

The easiest is probably to use application plugin. Add apply plugin: ‘application’ to your build.gradle and set mainClassName = com.bla.MainRunner . To add arguments to your main class modify the run task and edit the args property run { args += ‘first_arg’ } Classpath is taken automatically from main sourceSet, if you want different one, … Read more

Why does const int main = 195 result in a working program but without the const it ends in a segmentation fault?

Observe how the value 195 corresponds to the ret (return from function) instruction on 8086 compatibles. This definition of main thus behaves as if you defined it as int main() {} when executed. On some platforms, const data is loaded into an executable but not writeable memory region whereas mutable data (i.e. data not qualified … Read more

Where are the the argv strings of the main function’s parameters located?

Here’s what the C standard (n1256) says: 5.1.2.2.1 Program startup… 2 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. If the value of argc is greater than zero, the array members argv[0] through argv[argc-1] inclusive … Read more

Can the main function be overloaded?

§3.6.1/2 (C++03) says An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but otherwise its type is implementation-defined. All implementations shall allow both of the following definitions of main: int main() { /* … */ } int main(int argc, char* argv[]) … Read more

Main method with generic parameter; why does it work?

This is because a type parameter has a bound: <T extends String> => String <T extends String & AutoCloseable> => String & AutoCloseable And the bytecode after erasure is the same as for the regular main declaration in both cases: public static main([Ljava/lang/String;)V JLS §4.4. Type Variables: The order of types in a bound is … Read more

in c++ main function is the entry point to program how i can change it to an other function?

In standard C (and, I believe, C++ as well), you can’t, at least not for a hosted environment (but see below). The standard specifies that the starting point for the C code is main. The standard (c99) doesn’t leave much scope for argument: 5.1.2.2.1 Program startup: (1) The function called at program startup is named … Read more