OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Python: Initialize variable in C with multiple nested structs as strings

  • Thread starter Thread starter user19471767
  • Start date Start date
U

user19471767

Guest
I want to generate C code via Python. The issue is that I want to initialise struct variables as Python strings which are deeply nested with other structs.

For example:

Code:
In header files, I have structs like this
typedef struct
{
  uint8_t  var1
  uint32_t var2
  float    var3
  Type1    var4
}Type2;

typedef struct
{
  uint8_t  var5
  uint32_t var6
  float    var7
}Type1;

in a C-File, I initialize a variable of Type2.
Type2 my_var;

Now i want in Python a list of strings like: my_var.var4.var5 and more nested my_var.var4.var6 my_var.var4.var7 my_var.var1 my_var.var2 my_var.var3

I use pyclibrary as module for parse .h and .c files.

Does Python has a function to do this easily?
<p>I want to generate C code via Python.
The issue is that I want to initialise struct variables <strong>as Python strings</strong> which are deeply nested with other structs.</p>
<p>For example:</p>
<pre><code>In header files, I have structs like this
typedef struct
{
uint8_t var1
uint32_t var2
float var3
Type1 var4
}Type2;

typedef struct
{
uint8_t var5
uint32_t var6
float var7
}Type1;

in a C-File, I initialize a variable of Type2.
Type2 my_var;

</code></pre>
<p><strong>Now i want in Python a list of strings like:</strong>
<code>my_var.var4.var5</code> and more nested
<code>my_var.var4.var6</code>
<code>my_var.var4.var7 </code>
<code>my_var.var1 </code>
<code>my_var.var2 </code>
<code>my_var.var3 </code></p>
<p>I use pyclibrary as module for parse .h and .c files.</p>
<p>Does Python has a function to do this easily?</p>
 

Latest posts

Top