[Bug c/15240] New: sizeof() doesn't work on struct fields

d dot yu dot bolkhovityanov at inp dot nsk dot su gcc-bugzilla@gcc.gnu.org
Sat May 1 11:32:00 GMT 2004


The sizeof operator fails to operate on struct fields, when they are specified
as "type.field".

Consider the following code:

---- BEGIN s.c ----
#include <stdio.h>

typedef struct {int x; int y;} s_t;

int main(void)
{
    printf("s=%d\n", sizeof(s_t.x));

    return 0;
}
---- END s.c ----

Gcc produces an error:

s.c: In function `main':
s.c:7: parse error before `.'

while applying sizeof() to a variable (e.g. "s_t v;" =>  "sizeof(v.x)") works
fine.  

This constraint seems absolutely strange -- there's no reason why sizeof of a
type's field can't be taken.

Of course, this problem can be overcome with a macro like
#define T_SIZEOF(type,field) sizeof(((type *)NULL)->field)
but this is weird...

-- 
           Summary: sizeof() doesn't work on struct fields
           Product: gcc
           Version: 2.96 (redhat)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: d dot yu dot bolkhovityanov at inp dot nsk dot su
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15240



More information about the Gcc-bugs mailing list