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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:42:04+00:00 2026-05-12T00:42:04+00:00

I have a linked list, which stores groups of settings for my application: typedef

  • 0

I have a linked list, which stores groups of settings for my application:

typedef struct settings {
  struct settings* next;
  char* name;
  char* title;
  char* desc;
  char* bkfolder;
  char* srclist;
  char* arcall;
  char* incfold;
} settings_row;
settings_row* first_profile = { 0 };

#define SETTINGS_PER_ROW 7

When I load values into this structure, I don’t want to have to name all the elements. I would rather treat it like a named array — the values are loaded in order from a file and placed incrementally into the struct. Then, when I need to use the values, I access them by name.

//putting values incrementally into the struct
void read_settings_file(settings_row* settings){
    char* field = settings + sizeof(void*);
    int i = 0;
    while(read_value_into(field[i]) && i++ < SETTINGS_PER_ROW);
}

//accessing components by name
void settings_info(settings_row* settings){
    printf("Settings 'profile': %s\n", settings.title);
    printf("Description: %s\n", settings.desc);
    printf("Folder to backup to: %s\n", settings.bkfolder);
}

But I wonder, since these are all pointers (and there will only ever be pointers in this struct), will the compiler add padding to any of these values? Are they guaranteed to be in this order, and have nothing between the values? Will my approach work sometimes, but fail intermittently?

edit for clarification

I realize that the compiler can pad any values of a struct–but given the nature of the struct (a struct of pointers) I thought this might not be a problem. Since the most efficient way for a 32 bit processor to address data is in 32 bit chunks, this is how the compiler pads values in a struct (ie. an int, short, int in a struct will add 2 bytes of padding after the short, to make it into a 32 bit chunk, and align the next int to the next 32 bit chunk). But since a 32 bit processor uses 32 bit addresses (and a 64 bit processor uses 64 bit addresses (I think)), would padding be totally unnecessary since all of the values of the struct (addresses, which are efficient by their very nature) are in ideal 32 bit chunks?

I am hoping some memory-representation / compiler-behavior guru can come shed some light on whether a compiler would ever have a reason to pad these values

  • 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-12T00:42:05+00:00Added an answer on May 12, 2026 at 12:42 am

    Under POSIX rules, all pointers (both function pointers and data pointers) are all required to be the same size; under just ISO C, all data pointers are convertible to ‘void *‘ and back without loss of information (but function pointers need not be convertible to ‘void *‘ without loss of information, nor vice versa).

    Therefore, if written correctly, your code would work. It isn’t written quite correctly, though! Consider:

    void read_settings_file(settings_row* settings)
    {
        char* field = settings + sizeof(void*);
        int i = 0;
        while(read_value_into(field[i]) && i++ < SETTINGS_PER_ROW)
            ;
    }
    

    Let’s assume you’re using a 32-bit machine with 8-bit characters; the argument is not all that significantly different if you’re using 64-bit machines. The assignment to ‘field‘ is all wrong, because settings + 4 is a pointer to the 5th element (counting from 0) of an array of ‘settings_row‘ structures. What you need to write is:

    void read_settings_file(settings_row* settings)
    {
        char* field = (char *)settings + sizeof(void*);
        int i = 0;
        while(read_value_into(field[i]) && i++ < SETTINGS_PER_ROW)
            ;
    }
    

    The cast before addition is crucial!


    C Standard (ISO/IEC 9899:1999):

    6.3.2.3 Pointers

    A pointer to void may be converted to or from a pointer to any incomplete or object
    type. A pointer to any incomplete or object type may be converted to a pointer to void
    and back again; the result shall compare equal to the original pointer.

    […]

    A pointer to a function of one type may be converted to a pointer to a function of another
    type and back again; the result shall compare equal to the original pointer. If a converted
    pointer is used to call a function whose type is not compatible with the pointed-to type,
    the behavior is undefined.

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

Sidebar

Related Questions

Let's say I have a class which, internally, stores a List of data: import
In my application, I have 2 list activities which can start one or the
I have made the following linked list which is not printing the list .The
I have a linked list that I want to sort part of, eg: std::sort(someIterator,
I have implemented a linked list as a self-referencing database table: CREATE TABLE LinkedList(
For my programming class I have to write a linked list class. One of
I have a piece of software which is linked against several libraries. They all
I have a table which stores 'links' between 2 people. In order prevent further
i have two mysql tables which are linked together and i need to show
I am trying to make a function that sorts the linked list,which sorts the

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.