#75 problem in static structure intialization

None
closed
Maarten Brock
None
5
2013-09-21
2010-04-30
Robert Ramey
No

problem initializing structures.

When I have code like

static struct s = {
const void (*fpr)();
...
...
} = {
...

I notice when tracing through with the debugger that the target of fptr is the ADDRESS of the function rather than the variable "fptr"

See attached code and asm list

Discussion

  • Robert Ramey
    Robert Ramey
    2010-04-30

    source code

     
    Attachments
  • Robert Ramey
    Robert Ramey
    2010-04-30

     
    Attachments
  • Robert Ramey
    Robert Ramey
    2010-04-30

     
    Attachments
  • Robert Ramey
    Robert Ramey
    2010-04-30

     
    Attachments
  • Robert Ramey
    Robert Ramey
    2010-05-01

    I tried to reproduce this in a small example but was unsuccessful. In my real application I made this go away by moving a const static array of structures from a local function context to file context.

    Robert Ramey

    void
    gps_simulate_proxy(){
    const static struct {
    INT16 gps_velocity; /* knots * 10 */
    angle_gps gps_course; /* degrees * 10 */
    INT16 airspeed; /* m/s * 8 */
    } test_data [] = {
    {97,1800,105},
    {97,-1722,105},
    {97,-1644,105},
    {97,-1567,105},
    {98,-1489,105},
    ....
    static UINT8 i = 0;
    last.as_8 = test_data[i].gps_course;
    gbvario_gps_velocity_task(test_data[i].gps_velocity);
    gbvario_gps_heading_task(test_data[i].gps_course);
    if(++i > sizeof(test_data) / sizeof(test_data[0]))
    i = 0;
    }

    to

    const static struct {
    INT16 gps_velocity; /* knots * 10 */
    angle_gps gps_course; /* degrees * 10 */
    INT16 airspeed; /* m/s * 8 */
    } test_data [] = {
    {97,1800,105},
    {97,-1722,105},
    {97,-1644,105},
    {97,-1567,105},
    {98,-1489,105},
    ...
    void
    gps_simulate_proxy(){
    static UINT8 i = 0;
    last.as_8 = test_data[i].gps_course;
    gbvario_gps_velocity_task(test_data[i].gps_velocity);
    gbvario_gps_heading_task(test_data[i].gps_course);
    if(++i > sizeof(test_data) / sizeof(test_data[0]))
    i = 0;
    }

     
  • Maarten Brock
    Maarten Brock
    2010-05-01

    I fail to see the relationship between your two posts.

    Function pointers are difficult because according to spec you can dereference them both with and without the dereference operator esp. when calling them.

    And is fpr a typing error of fptr?

     
  • Maarten Brock
    Maarten Brock
    2011-11-05

    • status: open --> pending
     
  • Maarten Brock
    Maarten Brock
    2011-11-05

    Since there were no updates in 1.5 year and I still don't get what the question is, I set this item pending.

     
  • Maarten Brock
    Maarten Brock
    2013-09-21

    • status: pending --> closed
    • assigned_to: Maarten Brock
    • Group: -->