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

  • SEARCH
  • Home
  • 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 9183563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:50:08+00:00 2026-06-17T18:50:08+00:00

I’m currently making a small library which can access random.org and get random strings

  • 0

I’m currently making a small library which can access random.org and get random strings or integers. I’ve run into a slight problem now though, design wise, and I can’t decide which of my two approaches that would be the best, so I will write down my thoughts about both and ask the questions that I find relevant to both.

I currently have a struct like this:

typedef struct {
char **array;
size_t row;
size_t col;
size_t size; 
} MemoryStruct;

And this is the source of my “problem”, as I now have added in integer handling into my library.

As it can be seen, the pointer is currently a char pointer, and as I want to be able to handle blot integers and chars, should I add another pointer – an integer pointer – or should I instead make it a void pointer and make a function that will return the correct type of pointer?

The addition of an integer pointer would be the easiest, but I’m not sure how obvious it would seem to the guy who might use my library at some point in the future, that this is why his program segfaults, because he used the wrong pointer in the struct.

However, adding in a void pointer instead means that I will have to do a context based function that will return a pointer of the correct type (if this is even possible – I quite honestly don’t know if it is), which leads to the question:

Which return type would a function that can return different kinds of pointers have? (… it’s obvious, a void pointer!) but then I still don’t have the wanted type included for easy use for the programmer who’re using my library – here is it put into pseudo code what I would like to do.

pointer-with-type-info *fun(MemoryStruct *memory, RandomSession *session)
switch case on session->type
return pointer of appropriate type

It should be added here, that from session->type it can inferred which type the pointer should be.

Thank you in advance for reading this.

  • 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-17T18:50:09+00:00Added an answer on June 17, 2026 at 6:50 pm

    The way I understood your question, you know the pointer data type. I would use a void* instead of two pointers, because you may add more data types later without creating more fields.

    To retrieve the correct value, one can create two functions: int getAsString(MemoryStruct, char** value) and int getAsInteger(MemoryStruct, int &value). These functions would return a non-zero value in case of success (true). This way, you will be able no only to retrieve the correct value, but also you will have a way to know whether the value can be retrieved at as this data type.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I would like to run a str_replace or preg_replace which looks for certain words
I have an array which has BIG numbers and small numbers in it. I
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am currently running into a problem where an element is coming back from
I am writing an app for my school newspaper, which is run completely online
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I

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.