Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7812701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:35:54+00:00 2026-06-02T04:35:54+00:00

I have a function that draws a circle using OpenGL, I would like to

  • 0

I have a function that draws a circle using OpenGL, I would like to pass it a structure containing the x and y coordinates and the radius. The problem is this same function has to be used with 3 different structures all containing the coordinates, radius and some other things that the draw function doesn’t use.

Is there some way to only have one argument for 3 different structures (only one is sent at a time).

I hope I’ve been enough precise.

PS : the functions have to be “abstract”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:35:58+00:00Added an answer on June 2, 2026 at 4:35 am

    Yes you can use a prototype like this:

    void foo(char type, void *data);
    

    Use the type to tell the function which struct to use the data as, and you’re good.

    struct c *prepareStructC(void);
    //...
    struct c *toto = prepareStructC();
    foo('c', toto);
    //...
    void foo(char type, void *data)
    {
      int x, y;
      switch (type)
      {
        case 'c':
          x = ((struct c*)data)->x;
          y = ((struct c*)data)->y;
          break;
        //...
      }
      //...
    }
    

    Second option, if you want to avoid a switch/case, and be able to add more struct types afterwards, without evolving foo, you can make sure all your structs begin with the necessary data, always in the same order, with the same type. This way you can make something like an “interface” from C++, and use abstract versions of the type:

    struct abstract
    {
      int x;
      int y;
      int radius;
    }
    
    struct a
    {
      struct abstract abs;
      //... other data ...
    }
    struct b
    {
      struct abstract abs;
      //... other data ...
    }
    struct c
    {
      struct abstract abs;
      //... other data ...
    }
    
    //Two choices : either you have:
    void foo(void *data)
    {
      int x,y,r;
      x = ((struct abstract*)data)->x;
      y = ((struct abstract*)data)->y;
      r = ((struct abstract*)data)->radius;
      //...
    }
    
    //OR Smarter way:
    void foo2(struct abstract *data)
    {
      int x,y,r;
      x = data->x;
      y = data->y;
      r = data->radius;
    }
    //Calling foo2 with:
    struct a *sa = prepareStructA();
    struct b *sb = prepareStructB();
    struct c *sc = prepareStructC();
    foo2(sa->abs);
    foo2(sb->abs);
    foo2(sc->abs);
    

    The second part of the second method allows you more flexibility, breaking down specific information in a subtype, enables you to put the abs part anywhere inside the struct a/b/c, and is better in the principle of a single purpose for a struct (Having coordinates and radius and other things inside a struct is not always the best.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple AS3 app that draws few circles using drawing api
I have a function that draws a collection of images to the canvas and
So we have a function DrawPoint(x,y) that draws a point, we have to draw
I have a little problem. I have a program that will draw wave function
I have a function that draws a rectangle on the screen (see createInfoPanel()) While
so I have some code that draws a path and a circle. the circle
I have a function that draw an image on graphics: private void DrawSmallImage(Graphics g)
I have some functions that use opengl to draw lines on the screen (health
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.