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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:02:22+00:00 2026-05-27T04:02:22+00:00

I’m writing an ANSI C program and have a bug somewhere I’m unable to

  • 0

I’m writing an ANSI C program and have a bug somewhere I’m unable to find. I’m new to C so don’t discount the obvious.

I have three files in use. The first is a header file I include in the other 2 files using #include “myheader.h”. Inside this header file I have, among other things, a function prototype of:

double function1(double *, double *, double *, int *, int, int);

The second file contains the main() function. This includes, among other things, the declaration of variable APRON as:

int APRON[8] = {1, 2, 3, 4, 5, 6, 7, 8};

Using gdb in this file I observe:

(gdb) p APRON 
$1 = {1, 2, 3, 4, 5, 6, 7, 8}

Then this array is passed to another file (file3) as an argument in the following function call:

zz = function1(aa, bb, cc, APRON, dd, ee);

In file3, the function is defined as:

double function1(double *aa, double *bb, double *cc, int *bins, int dd, int ee)  

When gdb enters this file3, I immediately observe:

(gdb) p bins
$3 = (int *) 0x7fffffffe390

although I fooled around with the formatting here (don’t really know what I’m doing) and observed:

(gdb) p bins[0]
$5 = 1
(gdb) p bins[1]
$6 = 2
(gdb) p bins[2]
$5 = 3
(gdb) p bins[3]
$6 = 4
(gdb) p bins[4]
$5 = 5
(gdb) p bins[5]
$6 = 6
(gdb) p bins[6]
$5 = 7
(gdb) p bins[7]
$6 = 8

Why did gdb change the output of this array? Also, interesting (in a bad way), I see:

(gdb) p sizeof(bins)
$36 = 8

when it should be 4*8 = 32 (as I observe when doing this in file2).

Can someone help me understand what’s happening to this array when it enters file3? (why it appears different here compared to just before it’s passed into file3). I should mention the other arrays (aa, bb, cc) show the same behavior, although the scalars (dd, ee) come through fine in file3.

  • 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-27T04:02:23+00:00Added an answer on May 27, 2026 at 4:02 am

    gdb pays attention to how your variables are declared.

    In the first file, APRON is declared as an array of int. So sizeof() returns the size of the whole array, and gdb’s p command displays the whole array.

    In the second file, bins is declared as a pointer to an int. The size of a pointer to an int is 8 bytes (assuming you’re on a 64 bit machine). And asking gdb to print the value of a pointer will produce a hex value just as you observed.

    However, you also observed that you can use bins as the base of an array and index it just like APRON — so you were able to get the array element values by saying bins[0], bins[1], bins[2], etc. Everything you report sounds just as I would expect it to.

    When you pass APRON to function1(), you’re just passing the address of the array. function1() knows nothing about the size of the array. Either your code has to know how long the array is and not run past the end of it, or you need to include another argument to function1() indicating the number of elements in the array.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.