Is main function mandatory in glsl shaders?

C++: Keeping Function after Main function and still working.?

  • Well, I was using C++ when I found out that you need to put a function before the function declaring it otherwise it won't work. Is there any way to declare the Main Function first, then go to the other function (which is placed after the main function)? Otherwise it will become complicated because I have two functions that link to each other but depending on what you do in the program, one of them will come first. Help is appreciated greatly.

  • Answer:

    learn about function prototypes. a function prototype is a declaration of function that gives to the compiler necessary information before actually running it. void foo( int x ) ; //prototype void main() { //Code //................. //CALL foo( ) foo() ; //Code //.............. }//End main() //Now define: the foo() function void foo ( int x ) { cout<< x ; }

John Terrance at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Yes. You are allowed to declare a function before defining it. For instance, the following is perfectly legal: void whatever(int n); int main() { whatever(17); } void whatever(int n) { //do something } Interestingly, this also makes it possible for two functions to call each other. For instance: void func1(int n); void func2(int n) { if(n>0) { func1(n-1); } } void func1(int n) { if(n>0) { func2(n-1); } }

green meklar

Yes it is: void acoolfunction(int aint); //here you show that the function is there before showing it //whats there void main(){ Mainstuff; acoolfunction(Numberstuff); } //when you use { and } you basicly telling the computer that This is what inside there void acoolfunction(int aint){ FUNCTION STUFF; }

Vermacian55

You can DECLARE functions before the main() function then IMPLEMENT them afterwards. Try #include <iostream> using namespace std; typedef Board{...} void GetBoard(Board &Lifeboard); int Alive(Board Lifeboard); int main(){ ... return 0; } void GetBoard(Board &Lifeboard){ int i, j; for (i=0;i<MAXSIZE;i+=1)... Got it?

jplatt39

Usa a forward declaration int foo(int); .... int main(){ int x; int y; .... y=foo(x); .... return 0; } int foo(int n){ return 0; }

roger

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.