entry-point

How to change entry point of C program with gcc?

为君一笑 提交于 2019-11-26 18:41:10
How to change the entry point of a C program compiled with gcc ? Just like in the following code #include<stdio.h> int entry() //entry is the entry point instead of main { return 0; } It's a linker setting: -Wl,-eentry the -Wl,... thing passes arguments to the linker, and the linker takes a -e argument to set the entry function You can modify your source code as: #include<stdio.h> const char my_interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2"; int entry() //entry is the entry point instead of main { exit(0); } The ".interp" section will let your program able to call external

Avoiding the main (entry point) in a C program

懵懂的女人 提交于 2019-11-26 13:59:00
问题 Is it possible to avoid the entry point (main) in a C program. In the below code, is it possible to invoke the func() call without calling via main() in the below program ? If Yes, how to do it and when would it be required and why is such a provision given ? int func(void) { printf("This is func \n"); return 0; } int main(void) { printf("This is main \n"); return 0; } 回答1: If you're using gcc, I found a thread that said you can use the -e command-line parameter to specify a different entry

How can Android source code not have a main method and still run?

假如想象 提交于 2019-11-26 11:13:42
问题 I\'ve seen this in a few tutorials now... but how in the world can Android source code not have a main method and still run. For example (from http://developer.android.com/guide/tutorials/hello-world.html): public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } That runs but there is no main!!! I\'ve also thought that using

Is main() really start of a C++ program?

旧时模样 提交于 2019-11-26 10:13:45
The section $3.6.1/1 from the C++ Standard reads, A program shall contain a global function called main , which is the designated start of the program. Now consider this code, int square(int i) { return i*i; } int user_main() { for ( int i = 0 ; i < 10 ; ++i ) std::cout << square(i) << endl; return 0; } int main_ret= user_main(); int main() { return main_ret; } This sample code does what I intend it to do, i.e printing the square of integers from 0 to 9, before entering into the main() function which is supposed to be the "start" of the program. I also compiled it with -pedantic option, GCC 4

Replacing the WPF entry point

眉间皱痕 提交于 2019-11-26 08:03:14
问题 WPF defines its own Main() method. How should I go about replacing it with my own Main method that (normally) opens the WPF MainWindow (e.g. to add a non-WPF scripting mode via command-line arguments)? 回答1: Some examples depict changing App.xaml's Build Action from ApplicationDefinition to Page and writing your own Main() that instantiates the App class and calls its Run() method, but this can produce some unwanted consequences in the resolution of application-wide resources in App.xaml.

How to change entry point of C program with gcc?

冷暖自知 提交于 2019-11-26 03:55:58
问题 How to change the entry point of a C program compiled with gcc ? Just like in the following code #include<stdio.h> int entry() //entry is the entry point instead of main { return 0; } 回答1: It's a linker setting: -Wl,-eentry the -Wl,... thing passes arguments to the linker, and the linker takes a -e argument to set the entry function 回答2: You can modify your source code as: #include<stdio.h> const char my_interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2"; int entry() //entry

Is main() really start of a C++ program?

和自甴很熟 提交于 2019-11-26 03:27:58
问题 The section $3.6.1/1 from the C++ Standard reads, A program shall contain a global function called main , which is the designated start of the program. Now consider this code, int square(int i) { return i*i; } int user_main() { for ( int i = 0 ; i < 10 ; ++i ) std::cout << square(i) << endl; return 0; } int main_ret= user_main(); int main() { return main_ret; } This sample code does what I intend it to do, i.e printing the square of integers from 0 to 9, before entering into the main()

What are the valid signatures for C&#39;s main() function?

坚强是说给别人听的谎言 提交于 2019-11-25 23:05:38
问题 What really are the valid signatures for main function in C? I know: int main(int argc, char *argv[]) Are there other valid ones? 回答1: The C11 standard explicitly mentions these two: int main(void); int main(int argc, char* argv[]); although it does mention the phrase "or equivalent" with the following footnote: Thus, int can be replaced by a typedef name defined as int , or the type of argv can be written as char ** argv , and so on. In addition, it also provides for more (implementation