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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:10:33+00:00 2026-06-17T22:10:33+00:00

When I initialize a single element into a void structure, it works fine: void*

  • 0

When I initialize a single element into a void structure, it works fine:

void* CMD_ARRAY[] = 
{
  {"+++\r"},
  {"+++\r"},
  {"+++\r"},
};

However, when I try to add more elements to the structure, i.e.:

void* CMD_ARRAY[] = 
{
  {"+++\r" ,  4,  1300},
  {"+++\r" ,  4,  1300},
  {"+++\r" ,  4,  1300},
};

This results in an error:

expected a “}”

What is the difference between a single element as in the 1st example, and a structure of a structures (which are also considered as elements)?

How can I achieve initialization of this void structure with mixed types?

Update:
So I understand that the compiler doesn’t know how to handle different types in the same elements. Is there a way to define these types on the fly (i.e. using casting) without actually defining the structure outside this definition (i.e. using an array of strucutres)?

  • 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-17T22:10:34+00:00Added an answer on June 17, 2026 at 10:10 pm

    I would suggest that the compiler can’t guess certain details regarding your implicit struct declarations. For example, how is your compiler to guess that I wanted y in the example below to be a short?

    struct foo { char *x; short y; unsigned int z; };
    
    void* CMD_ARRAY[] = 
    {
      &(struct foo){"+++\r" ,  4,  1300},
      &(struct foo){"+++\r" ,  4,  1300},
      &(struct foo){"+++\r" ,  4,  1300},
    };
    

    This could be expanded at the cost of legibility to:

    void* CMD_ARRAY[] = 
    {
      &(struct { char *x; short y; unsigned int z; }){"+++\r" ,  4,  1300},
      &(struct { char *x; short y; unsigned int z; }){"+++\r" ,  4,  1300},
      &(struct { char *x; short y; unsigned int z; }){"+++\r" ,  4,  1300},
    };
    

    edit: In addition to the cost of legibility, consider what will happen if you decide to change your struct at the higher level. You’ll have to do plenty of finding/replacing in the lower level. Does this sound sweet to you?

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

Sidebar

Related Questions

How to initialize a single element to be true rather than initializing the whole
//initialize the people data list - (void)initializePeopleListFromJson:(CLLocationCoordinate2D)coordinate auraId:(NSString *)auraId { //initialize the NSMutableArray list
def initialize(apps, catch=404) @apps = []; @has_app = {} apps.each { |app| add app
I can initialize a List<int> like new List<int>{1,2,3,4,5}; However List<T> does not have a
As per suggestions I have modified the code, but how can I initialize single
I'm trying to print a single element from an array of 500 numbers. I
I have a UserCollection which is handled by a UsersView (list). Single elements, models,
I want to initialize a group of array elements the same value using a
The Bellman-Ford algorithm looks like this initialize-single-source(G,s) for i = 1 to |G.V| -
In a single operation, I am inserting multiple rows into a table. It is

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.