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 639003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:47:38+00:00 2026-05-13T20:47:38+00:00

I am a linguist in charge of a C program, so please excuse me

  • 0

I am a linguist in charge of a C program, so please excuse me if the answer is obvious. I have the following code:

typedef struct array_s {
  (...)
  void **value;
} array_t;
typedef array_t *array_pt;

array_pt array_new (int size) {
  (...)
  array->value = (void **)malloc(size*sizeof(void *));
}

void* array_get (array_pt arr, int i) {
  return arr->value[i];
}

int main () {
  int a = 1234;
  int *ptr = &a;

  array_pt array = array_new(1);
  array_add(array, ptr);

  printf("%i\n", (int)array_get(array, 0));
}

It is supposed to provide me with a multi-purpose array (for storing int and char*, if I understood I can only use void), and I guess there are no problems of allocating/freeing. However, I cannot get to cast it into anything useful (i.e., get back the “original” int/char*), and for what I understood it could be because I am in a 64-bit system and the size of a pointer to void is different from the size of a pointer to int/char* (the program is supposed to be used in both 64 and 32 bit systems). I tried using intptr_t and other alternatives, to no luck.

How can I be sure that the code will accept any data type and work on both 32 and 64 bit systems? Thank you.

EDIT:

Sorry for not adding array_add, here it is:

unsigned int array_add (array_pt array, void *ptr) {
  (...) // get the next index
  // allocate if needed
  array->value = (void **)realloc(array->value, array->size*sizeof(void *));

  array->value[index] = p;
}
  • 1 1 Answer
  • 2 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-05-13T20:47:39+00:00Added an answer on May 13, 2026 at 8:47 pm

    You need to dereference your pointer:

    int* temp = array_get(array, 0);
    printf("%i\n", *temp);
    

    However, I strongly recommend avoiding this type of approach. You’re basically giving away the small amount of help the compiler in C will normally provide – purposefully trying to make non-typesafe arrays.

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

Sidebar

Related Questions

There are two forms of the QObject::tr() function I have been using for translating
Possible Duplicate: C# localization , really confusing me Could someone please share their localization
In my project i'm trying to use qt linguist. When i change the language
If we wrap strings in tr() we can use the linguist to translate qt
What is the license of Qt platform (Qt libraries, QT Creator, Designer, Linguist etc)
When I try to run pythontranscriber.py, it fails with the following error: Traceback (most
The Qt Linguist can be used to load different images depending on the language
The only tool I can find so far is https://github.com/github/linguist I am sure this
Detecting the MIME type of a file with PHP is trivial - just use
I'd like to know if a tool like ANTLR would be appropiate for parsing

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.