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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:07:32+00:00 2026-06-09T05:07:32+00:00

I try to get the address of some struct member in array of structures

  • 0

I try to get the address of some struct member in array of structures but i don’t want to use name of that member.

It should be something like this:

typedef struct{               
  unsigned char MrChar;
  unsigned short MrShort;
  unsigned long MrLong;
  unsigned char MrArray[5];
}tModule;

static tModule taModulesArray[MODULES_AMOUNT] = {  // MODULES_AMOUNT = 2
  {0x22, 0x3298, 0x92324583, "djsoe"}, // Module 1
  {0x33, 0x1843, 0x65644113, "gskwc"}, // Module 2  
};

unsigned long usGetMemberAddr(unsigned long ulModule, unsigned long ulMember){
  unsigned long Address;
  Address = abs(taModulesArray_BaseAddress - taModulesArray[ulModule].[ulMember]);
  return Address;
}

I need that for quick modification of configuration (in EEPROM) which is in different structs. So I try to do function which takes number of module and index of one of the module member and returns offset of for proper member.

If there is any possibility for something like that line before return?

  • 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-09T05:07:34+00:00Added an answer on June 9, 2026 at 5:07 am

    We can use the below logic also to find the offset of each memebers of a structure and then we can directly add it to the base addres of the particular instance of the structure variable.

    #define OFFSET(type, member)   ( (int) (& ( ((type *)(0))->member ) ) )
    
    int find_offset(unsigned long ulMember)
    {
        unsigned long off = 0;
    
        switch(ulMember)
        {
             case 1:
                 off = OFFSET(tModule, MrChar);
                 break;
             case 2:
                 off = OFFSET(tModule, MrShorc);
                 break;
             case 3:
                 off = OFFSET(tModule, MrLong);
                 break;
             case 4:
                 off = OFFSET(tModule, MrArray);
                 break;
        }
    
        return off;
    }
    
    unsigned long usGetMemberAddr(unsigned long ulModule, unsigned long ulMember)
    {   
        unsigned long Address;   
    
        Address = (unsigned long)&taModulesArray[ulModule] + find_offset(ulMember);
    
        return Address; 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to try and get the ip address of a client after calling
I have some code in an asp.net app that needsto get the ipv4 address
I try get a my attribute inside Fancybox, and I get when I use
i try to get my FragmentPagerAdapter working, but the examples are a bit to
I try to get some website attribute (colour of the cell) and compare in
I try to get the name of executable name of all of my launched
I have a double link list that stores some information. When I try and
I try to get some data from Google Geocoding API with C# and ASP.net.
I try to access some values in a NSMutableArray I created, but I only
I try to get the whole content between an opening xml tag and it's

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.