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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:36:20+00:00 2026-05-29T05:36:20+00:00

Consider: struct { char *rcssMonitoredServices; int nSomeVar; } appinfo; In conventional use: appinfo.rcssMonitoredServices=strdup(something); However

  • 0

Consider:

struct
{
  char *rcssMonitoredServices;
  int  nSomeVar;
} appinfo;

In conventional use:

appinfo.rcssMonitoredServices=strdup("something");

However now consider:

char *RefToStructVar[]=
{
  appinfo.rcssMonitoredServices,
  "\0"
};

The intent being that we may perform operations against appinfo.rcssMonitoredServices using the RegToStructVar[0] pointer.

There are good reasons why I have variables pointed to within arrays. In cases of integer variables, we’re A-OK. Pointers to *char are quite different.

If I am doing the same technique against appinfo.nSomeVar

int *varpointers[] =
{
    &appinfo.nSomeVar,
    0
};

varpointers[0]=196;
printf("%i",appinfo.nSomeVar) // -> "196"

I thought that, given RefToStructVar[0] contains a pointer to the appinfo.rcssMonitoredServices, doing things like

RefToStructVar[0]=strdup("something");

Would be identical to:

appinfo.rcssMonitoredServices=strdup("something");

But no.

This

RefToStructVar[0]=strdup("something");

segfaults.

Perhaps basic.. but at the moment I am muddled.

—

later

Here’s what segfaults:

    struct 
    {
        char *cVar;
        int n;
    } mystruct;

    char *aVars[]=
    {
        mystruct.cVar,
        "\0"
    };

    aVars[0]=strdup("something");

This works:

    struct 
    {
        char *cVar;
        int n;
    } mystruct;

    char **aVars[]=
    {
        &mystruct.cVar,
        "\0"
    };

    *aVars[0]=strdup("something");
  • 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-29T05:36:20+00:00Added an answer on May 29, 2026 at 5:36 am
    RefToStructVar[0]=strdup("something");
    

    Is not identical to

    appinfo.rcssMonitoredServices=strdup("something");
    

    Because although the two pointers point to the same memory, they are two different pointers, and assigning to one of them will not change the other.

    Also, there is absolutely no reason why RefToStructVar[0] = anything should segfault unless RefToStructVar is not an array but an invalid pointer or something. I think you are misdiagnosing the crash site.

    You say:

    The intent being that we may perform operations against appinfo.rcssMonitoredServices using the RegToStructVar[0] pointer.

    However, that’s not what it’s doing. It’s simply copying the pointer from appinfo into the array. You can do operations on the string such as changing a character that way, but if you assign to either one, they become independent. You need a pointer to a pointer if you want to do that:

    char** RegToStructVar[] = {
        &appinfo.rcssMonitoredServices
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider something like: struct Parameter { int a; Parameter(){a = 0;} void setA(int newA){a
Consider: struct mystruct_A { char a; int b; char c; } x; struct mystruct_B
Consider this POD: struct T { int i; char c; }; In which C++
Consider this piece of code: struct Trade { float Price; char* time; int shares;
Consider the following code struct foo { const int txt_len; const int num_len; char
Consider the following: typedef struct { int a; int b; int c; int d;
Consider the following code: template <int dim> struct vec { vec normalize(); }; template
I have a type which I consider use it as struct. It represents single
Consider the following struct: public struct vip { string email; string name; int category;
Consider I have Struct like the following: struct Bitmask { unsigned char payload_length: 7;

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.