error: invalid application of 'sizeof' to incomplete type

Feb 28, 2011 at 5:56pm
I'm running into an error when trying to update legacy code.

Small Portion of Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    if (WhichLayout == STD_LAYOUT)
    {
        int num_stand_fields = sizeof(StandardLayout)/sizeof(FirmFieldStruct);
        for (int i = 0; i < num_stand_fields; ++i)
        {
            if (StandardLayout[i].ReportCounts)
            {
                ReportOnField[StandardLayout[i].Id] = 1;
            }
        }
    }
    else if (WhichLayout == MATCH_LAYOUT)
    {
226     int num_match_fields = sizeof(MatchLayout)/sizeof(FirmFieldStruct);
        for (int i = 0; i < num_match_fields; ++i)
        {
            if (MatchLayout[i].ReportCounts)
            {
                ReportOnField[MatchLayout[i].Id] = 1;
            }
        }
    }


Error:
 
226: error: invalid application of 'sizeof' to incomplete type 'FirmFieldStruct []'


I'm not sure what is being done wrong here. This is not code I've changed.

Also, why would int num_stand_fields = sizeof(StandardLayout)/sizeof(FirmFieldStruct); be ok but int num_match_fields = sizeof(MatchLayout)/sizeof(FirmFieldStruct); cause an error?
Feb 28, 2011 at 6:04pm
Probably MatchLayout was only forward declared
Feb 28, 2011 at 6:06pm
Yes, this is true. Why would this cause a problem? What can be done here to fix it?
Feb 28, 2011 at 6:10pm
The compiler can't tell the size of an object just from a forward declaration (for obvious reasons: there's nothing there but a name). You'll need to #include the proper header to use that approach.
Feb 28, 2011 at 6:26pm
I understand what went wrong. Thank you.
Topic archived. No new replies allowed.