public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/15240] New: sizeof() doesn't work on struct fields
@ 2004-05-01 11:32 d dot yu dot bolkhovityanov at inp dot nsk dot su
  2004-05-01 11:51 ` [Bug c/15240] " falk at debian dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: d dot yu dot bolkhovityanov at inp dot nsk dot su @ 2004-05-01 11:32 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-05-03  3:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-01 11:32 [Bug c/15240] New: sizeof() doesn't work on struct fields d dot yu dot bolkhovityanov at inp dot nsk dot su
2004-05-01 11:51 ` [Bug c/15240] " falk at debian dot org
2004-05-01 12:03 ` d dot yu dot bolkhovityanov at inp dot nsk dot su
2004-05-01 12:06 ` falk at debian dot org
2004-05-01 12:25 ` schwab at suse dot de
2004-05-02  7:39 ` d dot yu dot bolkhovityanov at inp dot nsk dot su
2004-05-03  3:40 ` bangerth at dealii dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).