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 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

Ask A Question

Stats

  • Questions 180k
  • Answers 180k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I've moved this question to stackoverflow.com/questions/1272398 The answer is posted… May 12, 2026 at 4:04 pm
  • Editorial Team
    Editorial Team added an answer Are you joining the multicast group first? You have to… May 12, 2026 at 4:04 pm
  • Editorial Team
    Editorial Team added an answer Usually I would treat behaviour and persistence as two different… May 12, 2026 at 4:04 pm

Related Questions

I've created a simple project with an SQL Server database with dozens of tables
I have some questions about cakePHP, I spent long time Googling for a solution
Well, after a long time writing .net programs in C# I started to feel
I talked to the Team Lead at Snap-On Tools once, and she told they

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.