October 23, 2024
Chicago 12, Melborne City, USA
C#

Is it correct to use GPtrArray for an array of strings (char*) in C?


I’m using GLib and C to make an application wherein I need to store a list of strings (i.e, a list of char*). Initially, I thought I would use GList or GArray, but then it hit me that strings just are pointers, so GPtrArray might be easiest to use, and so I used it. The only issue I encountered is that I have to cast the value back to a char* when accessing it via g_ptr_array_index as otherwise I just get a gpointer/void* back. However, it despite it feeling wrong to me (I’m not particularly experienced with writing C code), it seems to work just fine.

As such, I ask, is it correct to use GPtrArray for storing an array of strings in C?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video