* cc bugs?
@ 1996-07-20 4:00 philips
1996-07-22 4:00 ` Stephen Baynes
1996-07-22 4:00 ` Joe Mario
0 siblings, 2 replies; 6+ messages in thread
From: philips @ 1996-07-20 4:00 UTC (permalink / raw)
#include <stdio.h>
main()
{
unsigned long E1 = ~0 ;
printf("%lu %lu %d %d\n",E1 >> 1, E1/2,0x20,'\x20');
return 0;
}
Found what I think are 2 bugs in the standard Digital UNIX
cc compiler this week.
Not sure of the OS version, but I think it is 3.2 patch
level 148.
The first one is that >> on a full unsigned long of
1 bits fails to do anything. This is a standard trick
I use to to find the largest +ve 2 complement number.
The second is that the compiler does not recognise hex
chars. It was leathfull because I had it in a test
for characters below space which cause a lookup on a
table to core dump.
if ( khar < 'x20)
tbl[khar].xxxx
I'll be interested to hear if anyone agrees with my
findings.
I am posting this from an Internet Cafe so please email
any responses to:
philips@jse.co.za
Regards Philip Shearer
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: cc bugs?
1996-07-20 4:00 cc bugs? philips
@ 1996-07-22 4:00 ` Stephen Baynes
1996-07-22 4:00 ` Joe Mario
1 sibling, 0 replies; 6+ messages in thread
From: Stephen Baynes @ 1996-07-22 4:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 618 bytes --]
philips@jse.co.za wrote:
: The second is that the compiler does not recognise hex
: chars. It was leathfull because I had it in a test
: for characters below space which cause a lookup on a
: table to core dump.
: if ( khar < 'x20)
: tbl[khar].xxxx
I am suprised that compiled at all.
Try
if ( khar < '\x20')
tbl[khar].xxxx
--
Stephen Baynes baynes@ukpsshp1.serigate.philips.nl
Philips Semiconductors Ltd
Southampton My views are my own.
United Kingdom
Are you using ISO8859-1? Do you see � as copyright, � as division and � as 1/2?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: cc bugs?
1996-07-20 4:00 cc bugs? philips
1996-07-22 4:00 ` Stephen Baynes
@ 1996-07-22 4:00 ` Joe Mario
[not found] ` <31F4A4BE.6201@iisc.com>
1 sibling, 1 reply; 6+ messages in thread
From: Joe Mario @ 1996-07-22 4:00 UTC (permalink / raw)
To: philips; +Cc: mario
philips@jse.co.za wrote:
>
> #include <stdio.h>
> main()
> {
> unsigned long E1 = ~0 ;
> printf("%lu %lu %d %d\n",E1 >> 1, E1/2,0x20,'\x20');
> return 0;
> }
>
> Found what I think are 2 bugs in the standard Digital UNIX
> cc compiler this week.
>
> Not sure of the OS version, but I think it is 3.2 patch
> level
>
> The first one is that >> on a full unsigned long of
> 1 bits fails to do anything.
> The second is that the compiler does not recognise hex
> chars.
The default mode for C compilers on Digital UNIX is -std0, commonly
referred to as common or K&R mode. K&R C did not support hex escape
sequences. If you recompile in either of the ANSI modes, -std or
-std1, you'll find escape sequences are supported and you get the
results you expect.
Concerning your first problem, I ran your program and the output
did do the shift. Can you post the exact version of the OS and
show the output you're getting?
Thanks,
Joe Mario
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: cc bugs?
[not found] ` <31F4A4BE.6201@iisc.com>
@ 1996-07-23 4:00 ` Stephen Baynes
1996-07-23 4:00 ` Charles M Richmond
0 siblings, 1 reply; 6+ messages in thread
From: Stephen Baynes @ 1996-07-23 4:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1418 bytes --]
Charles M Richmond (cmr@iisc.com) wrote:
: #include <stdio.h>
: main()
: {
: unsigned long E1 = ~0 ;
: printf("%lu %x %lu %x %d %d\n",E1 >> 1,E1>>1,E1/2, E1/2,0x20,'\x20');
: return 0;
: }
: koibito.iisc.com> make junk
: cc junk.c -o junk
: koibito.iisc.com> junk
: 9223372036854775807 ffffffff 9223372036854775807 ffffffff 32 3158648
: koibito.iisc.com> cc -std -o junk junk.c
: koibito.iisc.com> junk
: 9223372036854775807 ffffffff 9223372036854775807 ffffffff 32 32
: koibito.iisc.com> cc -std1 -o junk junk.c
: koibito.iisc.com> junk
: 9223372036854775807 ffffffff 9223372036854775807 ffffffff 32 32
: koibito.iisc.com> uname -a
: OSF1 koibito.iisc.com V3.2 41 alpha
: So it is broken on 3.2d...
Looks like the '\x20' is broken for the first compile.
I think the the rest of the stuff looks OK. The problem is you have used %x
rather than %lx for the hex prints so are printing 32 rather than 64 bits and
I belive your long is 64 bits.
[A quick calculation with dc gives
2^32-1 as 18446744073709551615 ~(long)0
2^31-1 as 9223372036854775807 (~(long)0) >> 1
]
--
Stephen Baynes baynes@ukpsshp1.serigate.philips.nl
Philips Semiconductors Ltd
Southampton My views are my own.
United Kingdom
Are you using ISO8859-1? Do you see � as copyright, � as division and � as 1/2?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: cc bugs?
1996-07-23 4:00 ` Stephen Baynes
@ 1996-07-23 4:00 ` Charles M Richmond
1996-07-25 4:00 ` Dan Pop
0 siblings, 1 reply; 6+ messages in thread
From: Charles M Richmond @ 1996-07-23 4:00 UTC (permalink / raw)
Stephen Baynes wrote:
>
> Charles M Richmond (cmr@iisc.com) wrote:
>
> : #include <stdio.h>
>
> : main()
> : {
> : unsigned long E1 = ~0 ;
> : printf("%lu %x %lu %x %d %d\n",E1 >> 1,E1>>1,E1/2, E1/2,0x20,'\x20');
> : return 0;
> : }
>
> : koibito.iisc.com> make junk
> : cc junk.c -o junk
> : koibito.iisc.com> junk
> : 9223372036854775807 ffffffff 9223372036854775807 ffffffff 32 3158648
> : koibito.iisc.com> cc -std -o junk junk.c
> : koibito.iisc.com> junk
> : 9223372036854775807 ffffffff 9223372036854775807 ffffffff 32 32
> : koibito.iisc.com> cc -std1 -o junk junk.c
> : koibito.iisc.com> junk
> : 9223372036854775807 ffffffff 9223372036854775807 ffffffff 32 32
> : koibito.iisc.com> uname -a
> : OSF1 koibito.iisc.com V3.2 41 alpha
>
> : So it is broken on 3.2d...
>
> Looks like the '\x20' is broken for the first compile.
> I think the the rest of the stuff looks OK. The problem is you have used %x
> rather than %lx for the hex prints so are printing 32 rather than 64 bits and
> I belive your long is 64 bits.
>
> [A quick calculation with dc gives
> 2^32-1 as 18446744073709551615 ~(long)0
> 2^31-1 as 9223372036854775807 (~(long)0) >> 1
> ]
>
> --
You are of course correct. The one is arguably an error in that
the compiler follows K&R by default instead of the current
ansi standards. The other is a bonehead oversight on my part.
Mea Culpa!! (-:
Charlie
*************************************************************************
* Charles Richmond Integrated International Systems Corporation *
* cmr@iisc.com cmr@koibito.iisc.com cmr@shore.net *
* UNIX Internals, I18N, L10N, X, Realtime Imaging, and Custom S/W *
* One Longfellow Place Suite 3309 , Boston , Ma. USA 02114-2431 *
* (617) 723 7695 (617) 367 3151 FAX (617) 723 6861 *
*************************************************************************
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: cc bugs?
1996-07-23 4:00 ` Charles M Richmond
@ 1996-07-25 4:00 ` Dan Pop
0 siblings, 0 replies; 6+ messages in thread
From: Dan Pop @ 1996-07-25 4:00 UTC (permalink / raw)
In <31F55628.63DE@iisc.com> Charles M Richmond <cmr@iisc.com> writes:
>You are of course correct. The one is arguably an error in that
>the compiler follows K&R by default instead of the current
>ansi standards. The other is a bonehead oversight on my part.
Traditionally, cc is the K&R front end of the C compiler on a Unix system.
If you need to invoke the compiler in ANSI mode, just use the c89 front
end.
This is particularly handy when dealing with multiple platforms, because
it avoids you the need of remembering (or figuring out) the magic cc
incantation required to invoke the C compiler in ANSI mode on each
platform. c89 is a standard POSIX.2 feature, hence it is supported by
many vendors, including HP, DEC and IBM.
Dan
--
Dan Pop
CERN, CN Division
Email: Dan.Pop@cern.ch
Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~1996-07-25 4:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-07-20 4:00 cc bugs? philips
1996-07-22 4:00 ` Stephen Baynes
1996-07-22 4:00 ` Joe Mario
[not found] ` <31F4A4BE.6201@iisc.com>
1996-07-23 4:00 ` Stephen Baynes
1996-07-23 4:00 ` Charles M Richmond
1996-07-25 4:00 ` Dan Pop
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox