[comp.lang.c] Portability of C

dcw@icdoc.UUCP (04/10/87)

In Article 1154 of comp.lang.c, ron@brl-sem.ARPA, mentions, in a discussion
on portability :

> 3.  Saying int when you mean long...
> 	Of course there is no way to determine this really portably,
> 	but you can make a small machine header file that sets up
> 	typedefs appropriately.

One thing which always irritates me with C is that there is no way
to define data sizes portably...

When I just want an integer variable, on the assumption "oh well,
it had BETTER be big enough", then I just use 'int'

Otherwise, there is a (known) specific size/range of data which I want
to store.  So, I want to use
	'byte'		8 bits
	'word'		16 bits
	'long'		32 bits
	'megalong'	64 bits		(ok, so I made this one up :-)

(occasionally with 'unsigned' preceding it)

So, what earthly USE is the current definition of 'short', 'int' and 'long' ?

Are there cases (the simpler the better :-) when the existing method is useful ?



2). In Article 1155 of comp.lang.c, bright@dataio.Data-IO.COM, says :

> How about allowing numbers to be specified in binary radix,
> as in 0b00110101 ? No existing code would be broken, and it
> would be very useful to those of us writing graphics code,
> ...
> As a corollary, support %b in printf and scanf.

I agree completely.  It would also be nice to allow someone to
add new 'printf-able' objects. [ But this is, of course, a much more
complex matter than just adding binary.. ]


3). In the same article, he also suggested :

> specifying floating numbers in hex radix.

Presumably just like VAX assembler ?

Seems like a good-ish idea.  Probably wouldn't be used much, but would
be very useful when it is needed !


Duncan.

flaps@utcsri.UUCP (04/17/87)

In article <422@ivax.doc.ic.ac.uk> dcw@doc.ic.ac.uk (Duncan C White) writes:
>So, what earthly USE is the current definition of 'short', 'int' and 'long' ?
>Are there cases (the simpler the better :-) when the existing method is
>useful ?

ya, how about
    int i;
    for(i = 0; i < 10; i++)

:-)s aside, the point is, if you want to count from 1 to 10 you don't care
too much about the size of the integer (so long as it's not 3 bits or shorter,
I suppose), but it would be stupid to use a 16-bit integer on a 32-bit
machine or vice versa.

'int' is how you say "I don't care exactly how big this is."  Good style in C
involves using this approach as much as possible!  Just like not specifying
evaluation order, actually.

-- 

Alan J Rosenthal

flaps@csri.toronto.edu, {seismo!utai or utzoo}!utcsri!flaps,
flaps@toronto on csnet, flaps at utorgpu on bitnet.

"Probably the best operating system in the world is the [operating system]
made for the PDP-11 by Bell Laboratories." - Ted Nelson, October 1977