Sujet : Re: Integral types and own type definitions (was Re: Suggested method for returning a string from a C program?)
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 26. Mar 2025, 19:07:05
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vs26v2$2va7u$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
User-Agent : Mozilla Thunderbird
On 3/26/25 10:59, Janis Papanagnou wrote:
On 26.03.2025 12:33, David Brown wrote:
...
Even in C (in a desperate attempt to bring us back on topic for the
group), there are no negative integer constants - merely positive
integer constants with a unary minus operator applied.
Is that so? (Harmlessly asking.) - I mean, if I write int x = -5;
does it matter (in "C") whether its parsed as <integer number> or
<negation> <positive number> ?
It does make a difference in some contexts, but not in that one.
The problem I remember best is that if, for instance, the minimum
integer that can be represented by an int has the value -32768, then the
integer literal 32768 represents a value too big to be represented as an
integer, so it has the type 'long int' rather than 'int'. As result,
since the expression -32768 is parsed as the unary - operator applied to
32768, that expression also has the type 'long int'. That makes it
unsuitable as the #definition of INT_MIN. A popular alternative is to
#define INT_MIN as (-32767-1).
The same issue applies to INT_MIN regardless of what value it has, I
chose 16 bits only to reduce typing.