🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #41469

Re: Bug in TURBO-C V1.0

#41469
From: Mark Edwards
Date: Fri, 02 Mar 1990 10:39
51 lines
3208 bytes
In article <1990Feb21.204744.560@agate.berkeley.edu> ericco@stew.ssl.berkeley.edu (Eric C. Olson) writes:
#roland@cochise.pcs.com (Roland Rambau) writes:
#>hcj@lzsc.ATT.COM (HC Johnson) writes:
#>->> >    #define MAX  -32768
#>->> >    main()
#>->> >    {
#>->> >    printf("1: %d\n", MAX);
#>->> >    printf("2: %d\n", (int)MAX);
#>->> >    }
#>->> 
#>->> This is not a bug, its a feature.  MAX is not a number, its an expression.
#>->> Thus, the evaluation of MAX is a long int.  The first printf only prints
#>->K&R specify that constants are int's.  Not a long int.
#
#Like I said "MAX is not a number, its an expression."  There is an integer
#in the expression (the number 32768).  But there is also an operator (the
#unary minus).  This makes MAX an expression, not a number.  Thus the real
#question is what does K&R say integer expression are evaluated to?  I
#don't have K&R handy, but I believe it says long ints.
#
K&R, second edition, section A8.2 type specifiers offers these useful quotes:
1. If the type specifier is mission from a declaration, it is taken to be an int
2. The signed specifier is useful for forcing char objects to carry a sign; it
   is permissible but redundant with other integral types.
3. At most one of the words long or short may be specified together with int;
   the meaning is the same if int is not mentioned.

IMHO, MAX is a constant expression. Since its type is unspecified, it is an
int.  Since it is not specified as unsigned, and is an integral type, it is
therefore a signed type.  Together the conclusion that MAX is a
"const signed int MAX" when all the defaults are considered.  K&R say nothing
about the issue of long or short.  Neither does section A7.4.5 on the unary
minus operator.  The issue of long or short is probably best resolved in the
traditional manner i.e. an integer is the size of the native machine word.
This is 32 bits on a 68K.  A 8086 or 286 would be 16 bits by the same
tradition.  The native int on the 68K is then a long int, and on the Intel
it is a short int.  The expectation that short int means 16 bits and long
int means 32 bits is still meaningful.  The answer to the question is
machine architecture dependent.  For purposes of the discussion at hand, the
68K compiler should treat MAX as a signed 32 bit integer.

#Eric
#ericco@ssl.berkeley.edu
#


--
Mark C. Edwards             voice:      619/586-2204
Associate Systems Analyst   unix:       mce@pbsdts.pacbell.com
Matt 3:16-17,Acts 7:55-56,*John 8:17-18,*John 14:28,*Mark 13:32,
*John 20:17,*Matt 12:31-32,*John 17:20-23 (* Red letters) 
Technical Details
Message-ID: <8098@sdcc6.ucsd.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!sdcc6!sdcc10!mce
References: <8910270333.AA14741@cscwam.UMD.EDU> <0927891128429423@thelake.UUCP> <1990Feb14.173746.28244@agate.berkeley.edu> <1302@lzsc.ATT.COM> <1990Feb19.092139.3131@pcsbst.pcs.com> <1990Feb21.204744.560@agate.berkeley.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!sdcc6!sdcc10!mce
From: mce@sdcc10.ucsd.edu (Mark Edwards)
Newsgroups: comp.sys.atari.st
Subject: Re: Bug in TURBO-C V1.0
Message-ID: <8098@sdcc6.ucsd.edu>
Date: 2 Mar 90 10:39:54 GMT
References: <8910270333.AA14741@cscwam.UMD.EDU> <0927891128429423@thelake.UUCP> <1990Feb14.173746.28244@agate.berkeley.edu> <1302@lzsc.ATT.COM> <1990Feb19.092139.3131@pcsbst.pcs.com> <1990Feb21.204744.560@agate.berkeley.edu>
Sender: news@sdcc6.ucsd.edu
Organization: University of California, San Diego
Lines: 51