Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

g++-1.37.2: __typeof__(expr) can produce side-effects

1 view
Skip to first unread message

Jim Meyering

unread,
Aug 30, 1990, 1:36:38 PM8/30/90
to

gcc version 1.37.92
g++ version 1.37.2 beta (based on GCC 1.37)

It looks like ``__typeof__(*x++)'' evaluates the expression
and has the side-effect of incrementing `x.'

Here's a program to demonstrate the problem.
It exits with status=20. Compiling the same
program with gcc gives 10.

Please excuse me if this is a feature or a documented bug;
a search for `typeof' in the documentation did not tell me
whether it could produce side-effects.

--------
#define ABS(x) ({ \
__typeof__(x) _tmp = (x); \
(_tmp < 0) ? -(_tmp) : _tmp; \
})

int
sasum(int n, int* x)
{
int s = 0;
while (n-- > 0)
s += ABS(*x++);
return s;
}

int
main(int argc, char **argv)
{ int x[10] = { 1,2,3,4,5,6,7,8,9,10 }; return sasum(4,x); }

-------
% make
/p/bin/g++ -v -c main.cc -o main.o
g++ version 1.37.2 beta (based on GCC 1.37)
/p/lib/g++-1.37.2-beta/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ main.cc /usr/tmp/cca09587.cpp
GNU CPP version 1.37.2 beta (based on GCC 1.37)
/p/lib/g++-1.37.2-beta/gcc-cc1plus /usr/tmp/cca09587.cpp -quiet -dumpbase main.cc -version -o /usr/tmp/cca09587.s
GNU C++ version 1.37.2 beta (based on GCC 1.37) (sparc) compiled by GNU C version 1.37.92.
default target switches: -mfpu -mepilogue
/p/lib/g++-1.37.2-beta/gcc-as -o main.o /usr/tmp/cca09587.s
/p/bin/g++ -o xx main.o

--------
% xx
% echo $status
20
--
Jim Meyering meye...@cs.utexas.edu

0 new messages