Ending a function

Sid Kraft 96 Reputation points
2026-07-31T13:51:41.21+00:00
void display(void);
		{
			glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
			glClear(GL_COLOR_BUFFER_BIT);
			glLoadIdentity();
			glFlush();
		}
		 void glutInit(int* argcp, char** argv);
		 {
			 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH);
			 glutInitWindowPosition(100, 200);
			 //this sets the size for the window
			 glutInitWindowSize(800, 700);
			 //create the window with a title
			 glutCreateWindow("This is a window title");
			 //this is the method that will have all the draw stuff.	
			 glutDisplayFunc(display);
			 glutIdleFunc(display);
			 glutMainLoop();
			 return 0;
		 }
Strange, have been using the above functions, was told that the reason that the first function "display" does not work is because I have the semi colon after the (void). When I remove, get an error at the first "{" after the (void)? The second function also has the ";" after the function glutInit and it loads properly, without error. In any event, when I leave the ";" after each function, loads properly but get a linker error that states that the "display" function not found, very strange indeed, any help appreciated, Sid Kraft
Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.


3 answers

Sort by: Most helpful
  1. Taki Ly (WICLOUD CORPORATION) 3,700 Reputation points Microsoft External Staff Moderator
    2026-08-03T07:45:41.57+00:00

    Hello @Sid Kraft ,

    It appears the semicolon after void display(void); turns it into a function declaration rather than a definition, which likely causes the linker error. Removing the semicolon is the expected approach. If you see an error at { after removing it, this suggests there might be another syntax issue slightly earlier in your file.

    Additionally, glutInit is a built-in library function meant to be called, not redefined. It might be beneficial to move your window initialization code and the return 0; statement into a standard int main(int argc, char** argv) function.

    Below is a structure you could try:

    void display(void)
    {
        glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        glLoadIdentity();
        glFlush();
    }
    
    int main(int argc, char** argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH);
        glutInitWindowPosition(100, 200);
        glutInitWindowSize(800, 700);
        glutCreateWindow("This is a window title");
        glutDisplayFunc(display);
        glutIdleFunc(display);
        glutMainLoop();
        return 0;
    }
    

    Let me know if this helps resolve the build issues. If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation.

    Thank you.

    Was this answer helpful?


  2. RLWA32 52,786 Reputation points
    2026-07-31T14:27:07.5133333+00:00

    Had you simply followed the answers given at

    https://learn.microsoft.com/en-us/answers/questions/5962084/opengl-still

    and

    https://learn.microsoft.com/en-us/answers/questions/5961746/opengl-glutinit

    the problem with the display function would have been resolved.

    Was this answer helpful?


  3. AI answer

    2026-07-31T13:51:57.96+00:00

    The problem is the semicolon after the function declaration.

    In C++, this:

    void display(void);
    {
        ...
    }
    

    means:

    • void display(void); is only a declaration.
    • The following { ... } is just a separate block, not the body of display.

    That explains the linker error: display was declared, but never actually defined.

    The same issue exists for the other function. A function definition must not have a semicolon before its body.

    Also, glutInit is a GLUT library function, not a function to redefine. The code shown appears to be intended as main, because it ends with return 0;.

    Use this structure instead:

    void display(void)
    {
        glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        glLoadIdentity();
        glFlush();
    }
    
    int main(int argc, char** argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH);
        glutInitWindowPosition(100, 200);
        glutInitWindowSize(800, 700);
        glutCreateWindow("This is a window title");
        glutDisplayFunc(display);
        glutIdleFunc(display);
        glutMainLoop();
        return 0;
    }
    

    Key points:

    • Remove the ; after void display(void) when defining the function.
    • Do not define glutInit as a function. Call it from main.
    • return 0; belongs in main, not in a void function.

    If removing the semicolon causes an error at {, that usually means there is another syntax problem nearby, but the semicolon itself is definitely wrong for a function definition.


    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.