rfg@NCD.COM (Ron Guilmette) (09/16/90)
In article <1990Sep12.151529.7268@syd.dit.CSIRO.AU> evans@syd.dit.CSIRO.AU (Bruce.Evans) writes: >gcc-1.37 on a 386 gives strange results for sizeof on conditional >expressions. > >int a = sizeof (1 ? (char) 1 : (char) 1); /* 1, wrong? */ >int b = sizeof (1 ? (short) 1 : (short) 1); /* 2, wrong? */ >int c = sizeof (1 ? (char) 1 : (short) 1); /* 4, right */ >int d = sizeof (0 ? (char) 1 : (short) 1); /* 4, right */ >char e, f; >int g = sizeof (a ? e : f); /* 1, wrong? */ Even after re-reading section 3.3.3.4 of the ANSI C standard, I can't figure out what the proper values should be in the cases shown above. It appears that (contrary to the normal rule about implicit promotions of char & short expression operands to `int') that there are some special rules which prevent such promotions when the operands are used as arguments to sizeof(). Since these *exceptional* rules are never really spelled out very well, I'm unable to decide what the `right' values for the expressions shown above are. Can one of the comp.std.c gurus please say for sure what the `right' values are? (Note that the answers may be different in the case of C++.) -- // Ron Guilmette - C++ Entomologist // Internet: rfg@ncd.com uucp: ...uunet!lupine!rfg // Motto: If it sticks, force it. If it breaks, it needed replacing anyway.