main

How do I make main a friend of my class from within a library?

﹥>﹥吖頭↗ 提交于 2019-12-19 05:58:15
问题 Please see my first attempt at answering this . I neglected to tell the whole story before in an attempt to simplify things. Turns out my example works! Sorry. The whole story is that this is a library the contains a class in one file and the main in another file, all linked into my library. The library is providing the basis for a Process Framework, which is why the main is in the library and not the process. Below is a stripped down version of what I have. pf.hpp using namespace std;

What was Wrong with void main()?

拈花ヽ惹草 提交于 2019-12-18 14:18:09
问题 Why has setting the entry point's return type to void in C++ always been discouraged, and was later removed by the standard and is prohibited by modern compilers? Why is it considered bad practice? Now, as I understand C# and Java both allow the entry point's return type to be void i.e static void main(String[] args) /* Java */ static void Main(string[] args) /* C# */ And C# and Java programmers do not consider it bad practice, they use it often in fact. Other languages which are (only

How to determine main class at runtime in threaded java application?

▼魔方 西西 提交于 2019-12-18 14:14:14
问题 I want to determine the class name where my application started, the one with the main() method, at runtime, but I'm in another thread and my stacktrace doesn't go all the way back to the original class. I've searched System properties and everything that ClassLoader has to offer and come up with nothing. Is this information just not available? Thanks. 回答1: See the comments on link given by Tom Hawtin. A solution is these days is (Oracle JVM only): public static String getMainClassAndArgs() {

Using int Instead Of String: public static void main (int[] args)

独自空忆成欢 提交于 2019-12-18 13:35:48
问题 I was under the impression that the main method had to have the form "public static void main (String[] args){}", that you couldn't pass int[] arguments. However, in windows commandline, when running the following .class file, it accepted both int and string as arguments. For example, using this command will give the output "stringers": "java IntArgsTest stringers" My question is, why? Why would this code accept a string as an argument without an error? Here is my code. public class

Compiling with int main(void) fails; main(int argc, char *argv[]) succeeds. Why?

▼魔方 西西 提交于 2019-12-18 06:25:56
问题 Problem Why would compiling a program which has an int main(void) main function differ from compiling a program which has an int main(int argc, char *argv[]) main function, if the program does not use arguments passed on the command line? Is this OS or compiler specific? I do not get the same results using mingw and g++ (which is weird isn't it as wingw is a port of gcc) . Example Code #include <iostream> #include"SDL/SDL.h" int main(void) { return 0; } Compilation commands g++ test.cpp; #g++

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

二次信任 提交于 2019-12-18 04:17:13
问题 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 回答1: Solved the

Why the name main for function main()

廉价感情. 提交于 2019-12-18 03:36:19
问题 Why the function name main() is retained in many languages like C, C++, Java? Why not any other names for that function? Is there any common structure for all these 3 main() (in C, C++, Java) 回答1: There are a lot of silly and not very respectful answers here to a legitimate question. C didn't come from nowhere. Its immediate ancestor is B, written by Ken Thompson. Here is a link to the B manual. The basic structure of a B program is main(); exit(); main() is provided by the programmer and

C Main Loop without 100% cpu

空扰寡人 提交于 2019-12-17 22:47:09
问题 #include <stdio.h> int main() { while(!DONE) { /* check for stuff */ } return 0; } The above code sample uses 100% cpu until DONE is true. How can I implement a program that loops and only terminates when DONE, but which doesn't use 100% cpu? Modern languages use something like App.ProcessMessages or something like that to give the OS the control for the moment and then return to the loop. I'm new at C, obviously... using latest GCC, linux and windows (a portable solution would be great!) 回答1

C++ - char** argv vs. char* argv[]

Deadly 提交于 2019-12-17 22:04:05
问题 What is the difference between char** argv and char* argv[] ? in int main(int argc, char** argv) and int main(int argc, char* argv[]) ? Are they the same? Especially that the first part does not have [] . 回答1: They are entirely equivalent. char *argv[] must be read as array of pointers to char and an array argument is demoted to a pointer, so pointer to pointer to char , or char ** . This is the same in C. 回答2: They are indeed exactly the same. The golden rule of arrays to remember is: "The

Maven Error: Could not find or load main class

谁说我不能喝 提交于 2019-12-17 18:34:07
问题 I'm using a Java Maven program and I don't know what to enter as the <mainClass> . I've tried all kinds of things based off of numerous stackoverflow questions, but they are not solving the error. Each time it says: Maven Error: Could not find or load main class ... I have this written inside my pom.xml (minus the ??? ) <build> ... <plugins> ... <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.5.3</version> <configuration> <descriptors> <descriptor>src/main/assembly/jar-with