main

Two main functions

主宰稳场 提交于 2019-11-29 10:58:37
Can we have two main() functions in a C++ program? The standard explicitly says in 3.6.1: A program shall contain a global function called main, which is the designated start of the program. [...] This function shall not be overloaded. So there can one only be one one main function in the global scope in a program. Functions in other scopes that are also called main are not affected by this, there can be any number of them. Alex Martelli Only one function can be named main outside of any namespace, just as for any other name. If you have namespaces foo and bar (etc) you can perfectly well have

Is it safe to rename argc and argv in main function?

心已入冬 提交于 2019-11-29 10:29:43
问题 A lot of programs use standard names for a number of arguments and arrays of strings. The prototype of main function looks like: int main(int argc, char *argv[]); . But would I break something if I choose custom names for these variables? E.g. int main(int n_of_args, char *args[]); In the context of the compiler, everything is fine. These variables are local for main function, so they may have any names. And the simple code builds and runs perfectly. But these names may be used by

Non-standard signature of main() compiles successfully

强颜欢笑 提交于 2019-11-29 08:22:41
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? 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 standard environment (i.e. process command-line parameters and return an exit status), in which case you must use

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

牧云@^-^@ 提交于 2019-11-29 08:00:27
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? 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 this happens often enough that you should be aware of it. (I'm not sure if there's much you can do even if you

run main method using gradle “run” task

可紊 提交于 2019-11-29 05:29:13
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: JavaExec) { classpath "configurations.main" main = "com.bla.runners.StatsLogGenerator" args "arg1",

GCC: how to tell GCC to put the 'main' function at the start of the .text section?

跟風遠走 提交于 2019-11-29 04:33:27
I've just started learning some ARM programming and I've got stuck in a slightly annoying problem. The toolchain I'm using to compile my sources is Sourcery CodeBench Lite 2013.05-23 (can be found here: https://sourcery.mentor.com/GNUToolchain/release2449 ) What I would need is to tell GCC or LD or OBJCOPY to put the compiled bytecode of the 'main' function at the beginning of the .text section. Is there any way to achieve this? (maybe through a linker script?) Thank you Solved the problem. For whoever faces it: When compiling with GCC, add the -ffunction-sections option in the command-line.

“Could not find the main class: XX. Program will exit.”

僤鯓⒐⒋嵵緔 提交于 2019-11-29 03:44:57
I have managed to run my jar file with a command prompt, but its always giving me a reponse of Could not find the main class: XX. Program will exit. Please help me out, thanks. See Setting an Application's Entry Point If you have an application bundled in a JAR file, you need some way to indicate which class within the JAR file is your application's entry point. You provide this information with the Main-Class header in the manifest, which has the general form: Main-Class: classname The value classname is the name of the class that is your application's entry point. Recall that the entry point

Legal definitions of main() in C++14

二次信任 提交于 2019-11-29 01:12:12
The last draft of C++14 that I was able to find says, regarding main() [3.6.1]: 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 — a function of () returning int and — a function of (int, pointer to pointer to char) returning int and (paragraph 5) If control reaches the end of main without encountering a return statement, the effect is that of executing return 0; Does this mean that all of the following are legal C++14

How to access global variables

怎甘沉沦 提交于 2019-11-29 00:56:26
I'm fairly new to golang, this should be a simple answer but I've tried searching every where with no luck. How do I access a global variable that was declared/init in my main.go in a different .go package/file? Keeps telling me that the variable is undefined (I know that global variables are bad but this is just to be used as a timestamp) in main.go var StartTime = time.Now() func main(){...} trying to access StartTime in a different .go file but keep getting StartTime undefined I would "inject" the starttime variable instead, otherwise you have a circular dependency between the packages.

Multiple Main Functions

谁说胖子不能爱 提交于 2019-11-28 23:31:25
问题 I'm a bit new at this so bear with me. I'm currently learning C# and Java and one of their similarities is that the main function needs to be encapsulated within a class. For example public class HelloWorld { public static void main(String[] args) { // Some Code } } Now I understand that main is often the "entry point" when you run the program. So basically, your program will start executing wherever the main function is. But I believe in both languages you can have multiple main functions