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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:54:36+00:00 2026-05-30T15:54:36+00:00

I keep passing in and returning the dirs_later_array. When I get to new_size=… in

  • 0

I keep passing in and returning the dirs_later_array. When I get to “new_size=…” in the else block, I end up with new_size of 2 the second time around. So far so good. But when I do a realloc

dirs_later_array = realloc(dirs_later_array,
new_size * sizeof(struct dirs_later*));

the sizeof remains at 4, the size of the pointer, for dirs_later_array. I’m able to succesfully store at dirs_later_array[1] but that value keeps getting overwritten the next time I go into the function.

struct dirs_later** add_struct(const char *findme, struct dirent *dptr,
        struct stat *this_lstat, char *relative_path, const char *type_str,
        struct dirs_later **dirs_later_array) {

    struct dirs_later *new_dir = malloc(sizeof(struct dirs_later));
    check_realloc_dirs_error(new_dir);

    if (strcmp(dptr->d_name, ".")) { //Dir and not same directory
        //Copy the relative path to the struct
        char *relative_path2;
        relative_path2 = malloc(strlen(relative_path) + 1);
        check_realloc_error(relative_path2);
        strcpy(relative_path2, relative_path);

        //if (strlen(relative_path) > 0)
        //    relative_path2[strlen(relative_path) - 1] = '\0';

        if (NULL != new_dir) {
            new_dir->findme = findme;
            new_dir->dptr = dptr;
            new_dir->st_mode = this_lstat->st_mode;
            new_dir->relative_path = relative_path2;
            new_dir->type_str = type_str;
        }
        int new_size = 0;
        /*
         //Check if this is the first element in the struct
         if (sizeof(dirs_later_array) / sizeof(struct dirs_later*) == 1) {
         new_size = 1;
         }
         */
        if (dirs_later_array == NULL) {
            dirs_later_array = malloc(sizeof(struct dirs_later*)); //Store the directory structures or process later
            check_realloc_arr_error(*dirs_later_array);
            new_size = 1;
        } else {

            //Add directories to directories array
            new_size = (((sizeof(dirs_later_array) + sizeof(struct dirs_later*)))/sizeof(struct dirs_later*));
            //printf("new size: %d",new_size);
        }
        dirs_later_array = realloc(dirs_later_array,
                new_size * sizeof(struct dirs_later*));
        check_realloc_arr_error(dirs_later_array);
        dirs_later_array[new_size - 1] = new_dir;
    }
    return dirs_later_array;
}



  • 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-30T15:54:37+00:00Added an answer on May 30, 2026 at 3:54 pm

    Operator sizeof is a compile time feature and it only checks the static size of an expression. So for pointer it only returns the size of that pointer which is 4 on your platform. sizeof does not measure the size of a dynamically allocated data. There is no standard feature in C to get the size of dynamically allocated data.

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

Sidebar

Related Questions

Will using GetComInterfaceForObject and passing the returned IntPtr to unmanaged code keep the managed
Block syntax in Objective C (and indeed C, I presume) is notoriously incongruous. Passing
This might be either impossible or so obvious I keep passing over it. I
I'm passing around a partially applied function. The full signature is: import Data.Map as
I am passing in Dates into an Oracle stored procedure. I keep managing to
Possible Duplicate: C/C++: Passing variable number of arguments around I need to put all
I keep getting this exception (in the title) whenever I try to get the
I am parsing a HTML document with XPATH and I want to keep all
Keep in mind that I'm not looking for a list of current browsers to
Keep getting this error after inserting a subdatasheet into a query and trying to

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.