main

Is main() a pre-defined function in C? [duplicate]

99封情书 提交于 2019-12-07 04:51:50
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: main() in C, C++, Java, C# I'm new to programming in general, and C in particular. Every example I've looked at has a "main" function - is this pre-defined in some way, such that the name takes on a special meaning to the compiler or runtime... or is it merely a common idiom among C programmers (like using "foo" and "bar" for arbitrary variable names). 回答1: No, you need to define main in your program. Since it's

How do you pass arguments from command line to main in Flutter/Dart?

一曲冷凌霜 提交于 2019-12-06 23:41:25
问题 How would you run a command and pass some custom arguments with Flutter/Dart so they can then be accessed in the main() call such as: flutter run -device [my custom arg] So then I can access it with: void main(List<String> args) { print(args.toString()); } Thank you. 回答1: There is no way to do that, because when you start an app on your device there are also no parameters that are passed. If this is for development, you can pass -t lib/my_alternate_main.dart to flutter run to easily switch

Java running main method of other class, when JButton is pressed

时光毁灭记忆、已成空白 提交于 2019-12-06 21:30:28
I am trying to develop a JFrame which has two buttons that would let me to call the main method of other classes. The first try was to put it directly into the actionPerformed of each button, this will cause the JFrame of the other class to open but showing only the title of it and not showing any contents of the JPanel additionally freezing the program (can't even press close button, have to go into task manager or eclipse to kill it). The second try was adding a method call in actionPerformed, and adding the method will this time call the main method of other class however the same result

C# class without main method

我与影子孤独终老i 提交于 2019-12-06 19:51:36
问题 I'm learning C# and I'm very new to it, so forgive me for the seemingly stupid question. I have some experience in Java, and I noticed that C# programs also need a main() method in their main class. What if I want to create a class that isn't a main class, i.e. one that I import into a main class? I tried to do that, and when I compile (via cmd using csc File.cs ) the compiler says that the .exe that it will make has no main() method. Does that mean that I was wrong, and every class needs a

Is exit status observable behavior?

ε祈祈猫儿з 提交于 2019-12-06 18:26:14
问题 C 2018 5.1.2.3 6 says: The least requirements on a conforming implementation are: Accesses to volatile objects are evaluated strictly according to the rules of the abstract machine. At program termination, all data written into files shall be identical to the result that execution of the program according to the abstract semantics would have produced. The input and output dynamics of interactive devices shall take place as specified in 7.21.3. The intent of these requirements is that

Declaring main as friend considered harmful?

女生的网名这么多〃 提交于 2019-12-06 18:18:12
问题 Discussion I know that main can be a friend of a class : #include <iostream> class foo { friend int main(); int i = 4; }; int main() { foo obj; std::cout << obj.i << std::endl; } LIVE DEMO However, I feel that although this is perfectably allowable it conceals many dangers. Questions Are there any valuable uses in making main a friend of a class? Are there any reasons that declaring main as friend of a class should be considered harmful? 回答1: The choice whether to use or avoid a legal feature

Interthread communication

谁都会走 提交于 2019-12-06 16:32:54
The following question is about the unity game engine, but it could relate to any program trying to send data to a main thread, such as the UI thread. I am processing some data on a separate thread (position data a read asyncrously from a socket). However, I need to act on this data on the main thread (a game object's transform can only be accessed from the main thread). The approach I have in mind is to create a thread-safe queue and follow the producer-consumer pattern. The thread would queue the position data and the main thread would deque the data and act on it. *Note: In Unity I do not

How to fix “R.menu.main” in java when first developing an android app?

我与影子孤独终老i 提交于 2019-12-06 13:32:51
So I downloaded everything that the Android app tutorial told me to, and I am and using Eclipse, but I keep getting an error message on main in R.menu.main : public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; I've imported android.R; and it didn't work; I deleted that line and I went to Project>Clean and it still didn't fix itself. Other people on this topic keep saying to import the "R file" from your package but I checked all of the packages and classes and there

Can main() return structure?

六眼飞鱼酱① 提交于 2019-12-06 11:44:45
Yesterday in the interview one question was asked to me that can main return struct ? I have no idea can any one please tell me is it possible or not,if yes why? main can only return an int value in C (at least for hosted implementations ). Section 5.1.2.2.1 of the C standard says no: The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters: int main(void) { /* ... */ } or with two parameters (referred to here as argc and argv, though any names may be used, as they are

Is main() a User-Defined Function? [duplicate]

心已入冬 提交于 2019-12-06 11:37:01
This question already has answers here : main() in C, C++, Java, C# (9 answers) Closed 3 months ago . The programmer does define what happens inside main() , after all. So, should it be considered a user-defined function? The C++ standard doesn't have the notion of user-defined functions. Instead, it has the notion of library functions . main is not a library function. However, the standard also imposes some requirements on its signature, and that it must not be overloaded or declared static or inline. In particular, it must not be used , meaning that you cannot call it. Edit : I originally