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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:59:51+00:00 2026-05-26T00:59:51+00:00

I have a fixed-size array declared: int vals[25]; And I’d like to send the

  • 0

I have a fixed-size array declared:

int vals[25];

And I’d like to send the array to a function which will assign the values of vals:

bool FetchValueArray(char* source, char* name, char* typeFormat, int count, void** destination)
{
    int i;
    char *t;
    t=strstr(source,name);
    if (t)
        if (destination != NULL)
        {
            for (i = 0;i < count;i++)
                sscanf(t,typeFormat,destination[i]);
                return true;
        }
    return false;
}

This will essentially read everything at after a certain search string. For example:

FetchValueArray(source,"CONFIG=","%d",15,vals);

Where “CONFIG=” is in plain text, followed by 15 tab separated numeric values.

There’s something here I’m far from grokking about indirection and fixed aized arrays thus I’d like to know if a fixed sized array can be sent as a parameter as void** (even if there is the leap of faith that the size of the array will be respected. Different issue.)


tl;dr version

int vals[25];
bool foo(int size,void** d);
foo(25,vals);

Why is this not allowed?

  • 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-05-26T00:59:52+00:00Added an answer on May 26, 2026 at 12:59 am

    Arrays decay into pointers to their first elements, and pointers to any type can be implicitly cast to void*. Secondly, in order for array access to work properly, FetchValueArray needs to know how large each array element is. You’re trying to pass a void**, which is a pointer to a void*, so the array access treats each element as if it had the size of a void*, which is wrong — your array elements have size int, which is not necessarily the same as the size of a void*.

    So void** is wrong. You instead need to pass in void*, which means “pointer to unknown type”. You can’t use array indexing on a void*, since the compiler doesn’t know the size of the underlying pointed-to type. You need to help it out. For example:

    bool FetchValueArray(char* source, char* name, char* typeFormat, int count, void* destination, size_t destElementSize)
    {
        ...
        sscanf(t, typeFormat, (char*)destination + destElementSize * i);
        ...
    }
    ...
    FetchValueArray(source, "CONFIG=", "%d", 15, vals, sizeof(vals[0]));
    

    Here, we’re performing the array indexing manually — we’re casting the void* to char*, which has a known pointed-to size (1 byte), and then performing the array offset by multiplying by the per-element size. The result is a pointer to the proper memory location, which is what sscanf expects.

    Be very careful here, though — I think you should reconsider your design. The compiler doesn’t know the semantics of your function, so it can’t verify that you’re passing the proper arguments. It’s very easy to insert an accidental security vulnerability without realizing it here. Think about if you might be better off with a different design that the compiler can verify more thoroughly.

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

Sidebar

Related Questions

No related questions found

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.