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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:26:46+00:00 2026-05-17T17:26:46+00:00

**Updated. Sorry to those whose answers no longer make sense. So I figured out

  • 0

**Updated. Sorry to those whose answers no longer make sense.

So I figured out that no matter what I put on the line after Data_pair_node, after it executes, thats when the thing is reset! WTH? :

int insert(Table *t, const char *key, const char *val){
 int dest_bucket_index;
 Table *table = t;
 Hash_bucket *dest_bucket = NULL;
 Data_pair_node *current = NULL, *prev = NULL, *new_item = NULL;

 printf("gonna be zero now");

Lo and behold:

$23 = (Hash_bucket *) 0x834010
(gdb) step
109  printf("gonna be zero now");
(gdb) print table->buckets
$24 = (Hash_bucket *) 0x0

Thanks
Aymon Fournier

  • 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-17T17:26:47+00:00Added an answer on May 17, 2026 at 5:26 pm

    You’re using an integer divide (both list_count and table->bucket_ct are ints), so your result will be truncated and you’ll get a return value of 0 if the average bucket list length is less than 1.0 — if you have more buckets in the hash table than entries.

    Since you want a double answer, it makes more sense to use a double divide:

    ret = (double)list_count / table->bucket_ct;
    

    edit

    It’s tough to tell what’s going on as you never print out the value of table or show the code that calls insert (which is where it gets its value). But a couple of things might be going on.

    • table is a local var so the compiler might put it in a register and reuse that register for something else once table is dead (after the last use in the code), in which case printing table at that point (or anything depending on it) with gdb might print anything.

    • if table is a dangling pointer into the stack (it comes from another function that returned the address of a local variable), it might well be pointing at memory used for some other local vars, in which case assigning to those local vars will change the value of table->buckets

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

Sidebar

Related Questions

[Updated, sorry about the change but now to the real problem] I cannot include
UPDATE: sorry my IE 9 was'nt configured well: it should've been set so that
UPDATE Turns out I'm just tired. There isn't any problem here sorry for wasting
[Updated with partial answers, some more detailed questions.] Does CouchDB support multi-domain hosting? Yes,
First of all, sorry for the too long question. I know that there are
I have a custom binding that creates event handlers on init. In those event
[Sorry that English is not my native language.] So, I have a UI and
Sorry, that I have been posting here so often -- I have been doing
My webpage displays realtime data that is updated every 10 seconds from our PI
Ok, so I know that if the app gets updated, I should re-register with

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.