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

  • Home
  • SEARCH
  • 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 177151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:00:12+00:00 2026-05-11T14:00:12+00:00

I have created a dynamic typing system in C in order to create a

  • 0

I have created a dynamic typing system in C in order to create a dictionary that can contain values of different bit widths. The structure of the dynamic object is:

typedef struct {     void* Pointer;     unsigned char Size;    } Dynamic; 

I need to compare two of these Dynamics that hold A2D readings and then compare the difference against a delta value to determine if a change has occurred. One solution I have been able to come up with is to cast them to char arrays and compare them byte by byte, but that doesn’t smell right. I also have an idea to make an array of function pointers based on the number of bytes (or perhaps the type) the Dynamics take up and just make a comparison function for each type supported. Can anyone suggest a different approach? It feels like I am missing something.

UPDATE:

Thanks for telling me about memcmp, but I still have the problem of how do I get the delta of the two values? From what I can tell, memcmp just returns an indicator of which value is bigger, not the difference between them.

UPDATE TO UPDATE:

Its turns out that memcmp is useless to me because the architecture I am compiling against is little endian.

If I were going to do a bignum implementation myself then ephemient feels like the right way to go, but I have decided I am just going to memcpy the values into the largest possible type (i.e. unsigned long long) that I will have to deal with and just work the math using those. I can’t think of any reason why this would not work, but I recognize that I could be very wrong as C / direct memory manipulation is not my forte.

  • 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. 2026-05-11T14:00:13+00:00Added an answer on May 11, 2026 at 2:00 pm

    Is something like this sufficient?

    #include <string.h> int compare(Dynamic *a, Dynamic *b) {     if (a->Size != b->Size) return a->Size - b->Size;     return memcmp(a->Pointer, b->Pointer, a->Size); } 

    Creating a bunch of specialized functions if they perform very similar operations seems like overkill.

    Addendum

    If you want to calculate differences…

    int diff(Dynamic *a, Dynamic *b, Dynamic *d) {     int i, borrow = 0;     signed char *ap = a->Pointer, *bp = b->Pointer, *dp = d->Pointer;      assert(a->Size == b->Size && b->Size == d->Size);      for (i = 0; i < a->Size; ap++, bp++, dp++, i++) {         // symmetric difference         *dp = *ap ^ *bp;          // arithmetic difference, assuming little-endian         *dp = borrow += *bp - *ap;         borrow >>= 8;     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a static and dynamic library that I want to distribute. How
I have created a temporary table with dynamic columns. These columns are the values
Does python have the ability to create dynamic keywords? For example: qset.filter(min_price__usd__range=(min_price, max_price)) I
I have created a PHP-script to update a web server that is live inside
I have created a UserControl that has a ListView in it. The ListView is
I have created a few small flash widgets that stream .mp3 audio from an
i have created a workflow activity that do give the item creater of a
I have this problem where I can't get my dynamic data web app to
I have created a WinForm and I added to it dynamic Buttons, how I
I have Created a Procedure for one of our .Net Devs where they can

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.