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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:12:31+00:00 2026-06-10T03:12:31+00:00

In my Application I have struct: struct { gchar *xen_srv_addr; gchar *xen_srv_usr; gchar *xen_srv_psw;

  • 0

In my Application I have struct:

struct
{
  gchar *xen_srv_addr;
  gchar *xen_srv_usr;
  gchar *xen_srv_psw;
  gchar *xen_srv_prt;
} Xen_Server_Connection;

I want to assign a values to that gchars. I read it from file, parse with strtok and return as a char*.
Setting parser looks for specific tokens and:

if(a==b)
  {
    Xen_Server_Connection.xen_srv_addr=Parm_Pars(pattern, 2);
    .....
  }  

This assignment works only inside this if block.
gchar became garbage just after it. But if I:

if(a==b)
  {
    Xen_Server_Connection.xen_srv_addr="192.168.1.1";
    .....
  }

All seems ok and I can access to that gchar globally.
Seems I don’t understand 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-06-10T03:12:33+00:00Added an answer on June 10, 2026 at 3:12 am

    You don’t understand what lifetime guarantees the Parm_Pars() function gives on the returned value. It seems it doesn’t live forever, so you need to duplicate it if you want to hang on to it.

    Simply wrap that line in a call to g_strdup() to get a dynamically allocated copy and you should be fine. Of course, when you want to free your Xen_Server_Connection, you must call g_free() on all duplicated strings or you will leak memory.

    UPDATE: Mixing plain char and gchar is fine, glib guarantees that gchar is just an alias for char. I think they even recommend (somewhere) that applications never use gchar.

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

Sidebar

Related Questions

I have an MVC application. The model has a property that is a struct
I have a struct that's used in my internet application, which looks like: struct
I have an application that deals with data in the following structure: struct Message
In my C# application, I have a large struct (176 bytes) that is passed
In My application have time consuming process.There fore i try to do that operation
I have an application that reads times from a file. These times can be
I have an application that runs on embedded linux (older kernel, 2.6.18). I'm using
I have a C++ application which is sending a serialized struct to my C#
I have a c# .net 2.0 CF application that interfaces with a native DLL
I have a dll which accepts a struct that contains a pointer to a

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.