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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:05:53+00:00 2026-05-16T18:05:53+00:00

I have a C (not C++) struct that goes like this typedef struct mystruct{

  • 0

I have a C (not C++) struct that goes like this

typedef struct mystruct{
float a,b;
int x, y;
} mystruct;

Then in a function I collect data like this:

mystruct List[MAX];
ListNumber = 0;

for(i = 0; i < MAX; i++)
{
 if(conditions_meet)
 {
  List[ListNumber].a = masterlist[i].a;

…etc

ListNumber++;
 }
}

then I send the array to a function

 DoStuff(static int max, mystruct array[max]){
  Stuff
 }

This works, but when I try to do it like this….

mystruct setter(int i)
{
mystruct TEMP;
TEMP.a = masterlist[i].a;
 //......etc
return TEMP;
}


mystruct List[MAX];
ListNumber = 0;

for(i = 0; i < MAX; i++)
{
 if(conditions_meet)
 {
  List[ListNumber] = setter(i);
  ListNumber++;
 }
}

It causes a lot of funky errors. Why is this happening?
edit:
@tommieb75 I can’t give much detail, the results do not seem to have a pattern. The list is used as a generalized way to draw stuff to the screen, and having the function instead of the direct setting makes odd problems in rendering -and random-, but produce no compiler errors at all. gdb shows some integers as being larger than an integer, that’s the only pattern I find.
masterlist is a global array of another struct. The data needs to be converted to the struct in this example.
No compiler warnings or errors at all. I can turn in more sensitive warnings maybe, but I always get reported of any general error I can think.
I am going to try the selected solution, that should suffice. Anyway similar functions returning structs are used in my code and all work perfectly except for this case with an array of structs.

  • 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-16T18:05:54+00:00Added an answer on May 16, 2026 at 6:05 pm

    For a simple setting a struct member you need a copy from an entire struct-element?

    mystruct List[MAX];
    ListNumber = 0;
    
    for(i = 0; i < MAX; i++)
    {
     if(conditions_meet)
     {
      List[ListNumber].a = masterlist[i].a;
      ListNumber++;
     }
    }
    

    If you really need a function, use the destination-memory as parameter like:

    void setter(mystruct *dest,const mystruct *src)
    {
      dest->a = src->a; 
    }
    for(i = 0; i < MAX; i++)
    {
     if(conditions_meet)
     {
      setter( &List[ListNumber], &masterlist[i] );
      ListNumber++;
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dictionary that goes like this: typedef struct dictNode { int key;
I have a hierarchical data that goes like this: +----------------------+-------+ | name | depth
I have not had to do something like this in the past and am
I have not been able to find any definitive answers to this question: Can
I have an LLVM (version 2.7) module with a function that takes a pointer
I have class foo that contains a std::auto_ptr member that I would like to
I have some code that returns a struct containing 2 objects (declared as id
This is the edited code: I have a two dimensional stack, like #define push(s,ele)
I have a C++ library that provides various classes for managing data. I have
This question is related to this post : int to binary python I have

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.