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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:16:01+00:00 2026-05-29T08:16:01+00:00

It’s weird because I have done it before but it just is not working.

  • 0

It’s weird because I have done it before but it just is not working. I have a structure xmp_frame like this.

typedef struct {
    short int attr_dtype;
    short int attr_code;
    short int attr_len;
    const char *attr;
}xmp_frame;

Now I create an array of xmp_frame and use them like:

xmp_frame frame_array[]={
    {1,2,strlen("Hello there"),"Hello there"},
    {1,3,strlen("This is not working"),"This is not working"},
    {0,3,strlen("But why??"),"But why??"}
};

Now I have a routine which basically writes the frame_array in to file:

short int write_frames(xmp_frame frame_array[],FILE *outfp){

}

Before I write the frame_array I need to get the no. of elements in frame_array[] for doing some processing. So this is how we do it (generally):

short int write_frames(xmp_frame frame_array[],FILE *outfp) {
    short intnum_frames=sizeof(frame_array) / sizeof(frame_array[0]);
   /*But i get the value of num_frames as 0. I will print the outout of some debugging.*/ 

    fprintf(stderr,"\n Size of frame_array : %lu",sizeof(frame_array));  //prints 8
        fprintf(stderr,"\n Size of frame_array[0] : %lu",sizeof(frame_array[0])); //prints 16
       fprintf(stderr,"\n So num. of frames to write  : %d",  (sizeof(frame_array))/(sizeof(frame_array[0]))); //prints 0 
}

Of course if frame_array is 8 bytes and frame_array[0] is 16 bytes then num_frames is going to be 0.

But the question is how can size of an array be smaller than one of its elements? I heard about byte padding.

I don’t have much of an idea if it is causing the problem. Here is one of the links I referred to:
Result of 'sizeof' on array of structs in C?

Although I have found a few workarounds to determine the size of an array of structs.

  1. Get the no. of elements from the caller and

  2. another is compulsorily get the last struct element as {0,0,0,NULL} and then
    in write() check for it’s presence and stop scanning frame_array any further.

But both depend on the caller, something which you can’t trust.
So where is the real problem. And how could I determine the value of num_frames?

  • 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-29T08:16:02+00:00Added an answer on May 29, 2026 at 8:16 am

    Arrays are passed to functions as pointers, so the 8 bytes you are seeing is really the size of a pointer (assuming you’re on 64-bit) and not the size of the original array. There is no way to retrieve the actual size of the pointed-to array, so you’ll have to pass it separately to the function.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.