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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:31:52+00:00 2026-06-16T04:31:52+00:00

I have two data structures: typedef struct{ int a; int b; int c; }EVENTS;

  • 0

I have two data structures:

typedef struct{
    int a;
    int b;
    int c;
}EVENTS;

EVENTS typeone[20];
EVENTS typetwo[20];

These have been filled. typeone has been filled till typeone[5] and typetwo till typetwo[8].

I just want to compare the first six of typeone and typetwo and see if there are equal in all their members.

Is there a way to do typeone[1] == typetwo[1]
Basically comparing all the values inside the datastructure at [1].
Is there a short way to do this or would I have to loop through each member and compare separately?

Thanks

  • 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-06-16T04:31:53+00:00Added an answer on June 16, 2026 at 4:31 am
     typedef struct{
         int a;
         int b;
         int c;
     }EVENTS;
    
     #pragma pack(1)
         EVENTS typeone[20];
         EVENTS typetwo[20];
     #pragma pack()
    
     int equal(EVENTS* v1, EVENTS* v2)
     {
          return 0==memcmp(v1, v2, sizeof(*v1));
     }
    

    Note #pragma pack(1). It ensures that there are no padding bytes in the structures. This way memcmp will not try to compare padding bytes and the comparison is way faster than a field-by-field method, but while in this case the performance is unlikely to be adversely affected, take:

         typedef struct{
             char a;
             long b;
         } somestruct;
    
     #pragma pack(1)
         somestruct foo;
     #pragma pack()
    

    Retrieving foo.b will take much more machine code than in case of padded structures, because it will miss word-aligned position where it can be retrieved with a single 32-bit instruction, it will have to be picked out with four byte-reads, and then assembled into the target register from these four pieces. So, take the performance impact into account.

    Also, check if your compiler supports #pragma pack. Most modern compilers do, but exceptions may still happen.

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

Sidebar

Related Questions

I have these two data structures that I continually find myself choosing between when
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I have two data structures in Java: One is called DebateAssignment and has 5
I have these two data structures: public TreeMap<String, Integer> tableFrequency; public SortedSet<Map.Entry<String, Integer>> sortedTable;
I have two tables with the following (simplified) structures: table "Factors" which holds data
i have two data tables with the same structure the first one has one
I have two data models: Writer.AttributValeur and Writer.Produit . Writer.Produit has HasMany / BelongsTo
I have two files, one with webservice description (wsdl), second with data structures used
I have two tables with identical structures handling distinct data. I want to merge
I have two sources: an xml-file containing definitions of several hundred data structures, basically

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.