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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:39:45+00:00 2026-05-26T18:39:45+00:00

I need some help in C syntax, more about C casting syntax. All information

  • 0

I need some help in C syntax, more about C casting syntax.
All information I found in web is about simple casts like (int) or (char) etc…
I always get stuck in casting void* to a array or multi-dimentisional array or pointers of such things, but I never know how to do that! All that I do in these cases was trying things like (char []) or (char *[]) or (*char []) without any idea what I’m doing, until I get no errors about type casting.

Anybody have a thumb of rule to follow or some tips or tricks to do that?
For example I have a arry of void pointers and I pass it to a function, how to turn it into array again?

main () {
   int data1, data2;
   char data3, data4;
   void *function_data[] = {data1, data2, data3, data4};
   some_function (function_data);
   return;
}


some_function (void *data) {
   void *function_d[4];
   function_d = (void *[]) data; //It not work, how to cast data?
}

EDIT: I wrote wrong, I thinked that it wasn’t important, so, I changed the variables data* of my code for better undestand.

  • 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-26T18:39:46+00:00Added an answer on May 26, 2026 at 6:39 pm

    The basic idea is to use the type definition of the intended type without the variable name and placed in parentheses as a cast to that type. For example:

    int c;
    c = (int) 4;
    

    and

    char * (*functionptr)(float, double);
    functionptr = (char * (*)(float, double))myfunction;
    

    Of course always assuming the type cast is possible and makes sense. Be aware: C doesn’t prevent most nonsensical casts, so you’ll have to take care yourself.

    In your case, function_data is defined to be an array of pointers to void. Therefore, each data needs to be of type void **, as Keith already indicated.
    By calling some_function with function_data as parameter, you’re passing a pointer to function_data[0] into the function.
    In order for your function to use it again as an array of 4 pointers to void, you would need to use a cast like you did, (void*[]). However, the array function_d is an array reserving also the space for four pointers, and you cannot change the function_d pointer (it is of type void * * const!). To do what you seem to want, you’ll need a non-const pointer, like

    void * * function_d = (void*[])data;
    

    You may then still use it in the same way like function_data, using subscription like an array. function_d[2] will give you the value equal to *data3.

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

Sidebar

Related Questions

this might be really simple, but just need some help in getting the syntax
I need a little help with some Emacs syntax highlighting troubles. I'd like to
I need some help with simple SQL code: DECLARE @procExists int SET @procExists =
Need some help about with Memcache. I have created a class and want to
I need some help with jQuery syntax. I'm trying to modify the opacity effect
I just need some quick help on syntax. I'm doing a WPF project and
I need some help to complete my idea about regexes. Introduction There was a
i need some help with switch/case statement syntax im trying to use onClick to
I need some css and syntax help,please. Your help is warmly welcome. I want
I need some help with my syntax. I need the possibility to upload either

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.